Public Schedule Face-to-Face & Online Instructor-Led Training - View dates & book

pulling data ndtms website

Forum home » Delegate support and help forum » Microsoft Access Training and help » Pulling data from the NDTMS website

Pulling data from the NDTMS website

ResolvedVersion 365

Pulling data from the NDTMS website

Is it possible for me to use copilot to pull data by local authority from the NDTMS website? If so are there specific prompts I need to use?

RE: Pulling data from the NDTMS website

Hi Cat,

Thank you for the forum question.

Using Copilot and Power Query to obtain NDTMS data by local authority
Yes, it is possible to use Copilot and Excel to work with local-authority data from the NDTMS website.

The most reliable approach is to download the official NDTMS CSV containing the required local-authority data and import it into Excel using Power Query. Copilot can then help analyse, filter and present the imported data.

It is not advisable to rely entirely on Copilot to extract the information directly from the NDTMS webpage. The website uses interactive selections, and a direct extraction may omit records or combine different reporting periods and categories incorrectly.

A recommended process is:
1. Download the NDTMS CSV.
2. Import the CSV into Excel using Power Query.
3. Clean and structure the data.
4. Filter the data by local authority, reporting year and indicator.
5. Use Copilot to create summaries, comparisons, PivotTables and charts.
6. Refresh the Power Query connection when updated NDTMS data becomes available.

Example Copilot prompts
The following prompts can be used after the NDTMS data has been imported into Excel and loaded into an Excel table.
Filter one local authority
“Filter the NDTMS table to Greenwich. Keep the reporting year, treatment category, substance category, key indicator, count and proportion columns. Place the results on a new worksheet called Greenwich.”

Compare several local authorities
“Using the NDTMS table, compare Greenwich, Lewisham, Bexley and Southwark for each reporting year. Show the number of adults in treatment and the proportion represented by each substance category.”

Create a PivotTable
“Create a PivotTable showing local authority in rows, reporting year in columns and treatment count as values. Add substance category and treatment category as filters.”

Create a trend chart
“Create a line chart showing the number of adults in treatment in Greenwich by reporting year. Use a separate line for each substance category.”

Compare a local authority with England
“Compare Greenwich with the England value for each key indicator in the latest reporting year. Add a variance column showing the Greenwich value minus the England value.”

Check data quality
“Check the NDTMS table for duplicate records, blank local-authority values, inconsistent data types and missing reporting years. List the issues and identify the affected records.”

Create a reusable report
“Create a summary worksheet from the NDTMS table. Include a local-authority selector, latest-year headline figures, a year-on-year comparison and a trend chart by substance category.”

Copilot normally produces better results when the prompt identifies:
• The name of the Excel table
• The required local authority
• The reporting period
• The relevant columns
• The required filters
• The required output, such as a table, PivotTable, summary or chart

For complete and auditable reporting, the official CSV and Power Query should remain the main source of the data. Copilot should be used to assist with analysis and presentation.

Step-by-step Power Query workflow for the NDTMS CSV
1. Save the CSV file
1. Download the required CSV from the NDTMS website.
2. Create a permanent folder, for example:
C:\NDTMS\Data
3. Save the file with a consistent filename, for example:
NDTMS_Local_Authority.csv

When updated data becomes available, replace the existing CSV while retaining the same filename and folder location. This prevents the Power Query source connection from breaking.
2. Import the CSV into Excel
1. Open a new or existing Excel workbook.
2. Select the Data tab.
3. Select Get Data > From File > From Text/CSV.
4. Locate and select NDTMS_Local_Authority.csv.
5. Check that the delimiter is set to Comma.
6. If available, set data type detection to Based on entire dataset.
7. Select Transform Data.

The file will open in the Power Query Editor.
3. Rename the query
In the Query Settings pane, rename the query:
NDTMS_All_Data

This will be the master query containing the cleaned NDTMS dataset.
4. Check the column headings
Check whether the first row contains the correct column headings.
If the columns are named Column1, Column2, and so on:
1. Select the Home tab.
2. Select Use First Row as Headers.
The exact column names may differ between NDTMS releases. Typical fields may include:
• Geographic area
• Local authority
• Reporting year
• Treatment category
• Key indicator
• Substance category
• Sex
• Age group
• Count
• Proportion
5. Remove the automatic data type step

Power Query will normally create a Changed Type step automatically.
It is advisable to remove this step and assign the data types manually:
1. Find Changed Type under Applied Steps.
2. Select the X next to the step.
This prevents Power Query from incorrectly converting reporting years, suppressed values or other text fields.
6. Retain the required columns
Select the columns needed for the analysis. These may include:
• Geographic area
• Local authority
• Reporting year
• Treatment category
• Key indicator
• Substance category
• Sex
• Age group
• Count
• Proportion

After selecting the required columns:
1. Select Home.
2. Select Remove Columns > Remove Other Columns.
Before removing columns, confirm that all fields required for filtering, reporting and validation have been selected.
7. Clean the text columns
Select the descriptive text columns, such as:
• Local authority
• Geographic area
• Reporting year
• Treatment category
• Key indicator
• Substance category
• Sex
• Age group
Apply the following transformations:
1. Select Transform > Format > Trim.
2. Select Transform > Format > Clean.

Trim removes unnecessary spaces from the beginning and end of the values.
Clean removes non-printing characters that may cause apparently identical values to be treated as different values.
8. Assign the data types
Apply the following data types where appropriate:
Field Recommended data type
Geographic area Text
Local authority Text
Reporting year Text
Treatment category Text
Key indicator Text
Substance category Text
Sex Text
Age group Text
Count Whole Number
Proportion Decimal Number

A reporting year such as 2023/24 should remain as text. It should not be converted into a date.
9. Deal with suppressed and unavailable values
Before converting the Count or Proportion columns to numeric data types, check for values such as:
• Blank
• Hyphen
• Asterisk
• Suppressed
• Not available
These values can create errors when a column is converted to a number.
Where appropriate:
1. Select the relevant column.
2. Select Transform > Replace Values.
3. Replace the non-numeric marker with null.
4. Change the Count column to Whole Number.
5. Change the Proportion column to Decimal Number.
Suppressed or unavailable values should not normally be replaced with zero. A suppressed value does not necessarily mean that the result was zero. Replacing it with zero could distort totals, averages and comparisons.
If the original suppression marker must be retained:
1. Right-select the Count column.
2. Select Duplicate Column.
3. Rename the original column Count source.
4. Clean and convert the duplicated column.
5. Rename the duplicated column Count.
This preserves the published value while also providing a numeric column for analysis.
10. Check how proportions are stored
Check whether the Proportion column contains values such as:
• 0.237, representing 23.7%
• 23.7, representing 23.7%
If the values are between zero and one, they can be formatted as percentages after loading.

If the values are stored as numbers such as 23.7, they should either remain as decimal values or be divided by 100 before percentage formatting is applied.
To divide the values by 100:
1. Select the Proportion column.
2. Select Transform > Standard > Divide.
3. Enter 100.
4. Change the data type to Percentage.
The published NDTMS definition should be checked before changing the calculation.
11. Create a reference query
The master query should normally remain unfiltered. A separate reference query can be created for the required local authority.
1. Right-select NDTMS_All_Data in the Queries pane.
2. Select Reference.
3. Rename the new query:
NDTMS_Selected_LA
4. Apply the required filters to the new query.
A reference query uses the output of the master query. Any cleaning changes made to NDTMS_All_Data will therefore flow through to NDTMS_Selected_LA.
12. Filter the local-authority data
In NDTMS_Selected_LA:
1. Open the filter on the Local authority column.
2. Clear Select All.
3. Search for the required authority.
4. Select the correct value.
5. Select OK.
Check the precise geographical name used in the file. For example, the file may use Greenwich, Royal Borough of Greenwich or another published variation.
13. Apply the required reporting filters
Apply the relevant filters, for example:
• Local authority
• Reporting year
• Treatment category
• Key indicator
• Substance category
• Sex
• Age group
Care is required when the dataset contains both overall and detailed categories.
For example, the dataset may contain an All substance categories row as well as separate rows for individual substance categories. The overall row should not be added to the detailed rows, as this would double-count the population.
The same consideration applies to age groups, sex categories, treatment categories and other fields containing an All value.
14. Remove duplicate rows if necessary
Duplicates should only be removed when the records are genuinely identical.
Select all columns that define a unique NDTMS observation, for example:
• Local authority
• Reporting year
• Treatment category
• Key indicator
• Substance category
• Sex
• Age group
Then select:
Home > Remove Rows > Remove Duplicates
Do not remove duplicates based only on the Local authority column. This would retain one record per authority and remove all other observations.
15. Add a refresh timestamp
A refresh timestamp can be added to show when Power Query last processed the dataset.
1. Select Add Column > Custom Column.
2. Enter the column name:
Refreshed
3. Enter the following formula:
DateTime.LocalNow()
4. Set the new column’s data type to Date/Time.
This records when the query was refreshed. It does not represent the NDTMS publication date.
16. Load the queries into Excel
For the master query:
1. Select the arrow next to Home > Close & Load.
2. Select Close & Load To.
3. Select Only Create Connection.
For NDTMS_Selected_LA:
1. Select Close & Load To.
2. Select the required output:
o Table for a standard Excel worksheet
o PivotTable Report for summary reporting
o Only Create Connection and Add this data to the Data Model for a larger analytical model
17. Refresh the data

When updated NDTMS data becomes available:
1. Download the new CSV.
2. Replace the existing file in C:\NDTMS\Data.
3. Retain the filename NDTMS_Local_Authority.csv.
4. Open the Excel workbook.
5. Select Data > Refresh All.
Power Query will repeat the recorded cleaning, transformation and filtering steps using the updated CSV.
Recommended query structure
A practical workbook could contain the following queries:
• NDTMS_All_Data: cleaned master dataset, connection only
• NDTMS_Selected_LA: selected local authority, loaded to Excel
• NDTMS_LA_Comparison: optional comparison of several local authorities
• NDTMS_England: optional England-level benchmark
Final validation checks
Before using or distributing the results, confirm that:
• The correct local authority has been selected.
• The correct reporting year has been selected.
• Count and Proportion use the correct data types.
• Suppressed values have not been converted to zero.
• Overall rows have not been added to their detailed component rows.
• Different treatment categories have not been combined accidentally.
• The proportion field has been interpreted correctly.
• At least one result agrees with the figure shown on the NDTMS website for the equivalent authority, year and indicator.
This approach provides a controlled, auditable and refreshable process. Once the workbook has been created, updated NDTMS data can be processed by replacing the source CSV and selecting Refresh All.



Kind regards

Jens Bonde
Microsoft Office Specialist Trainer

Tel: 0207 987 3777
STL - https://www.stl-training.co.uk
98%+ recommend us

London's leader with UK wide delivery in Microsoft Office training and management training to global brands, FTSE 100, SME's and the public sector

Access tip:

Create a custom Close button on a Form

By default, Forms that you create in Access have a full set of control buttons, that is, a title bar with Minimize, Maximize and Close buttons in the top right-hand corner and a Control Menu in the top left-hand corner.



Sometimes Access needs to follow certain procedures or events as users close a Form (such as automatically opening another Form perhaps). So it is often a good habit to create a custom Close button on a Form for everyone to use, rather than the standard closing cross.



To create a custom Close button:

1) In Form Design View, draw a Command Button onto the Form.

2) Use the Command Button Wizard to select Form Operations under Categories, and Close Form under Actions.

3) Choose Finish.



Access then creates the button and code to close the form for you. You can add any extra code that needs to run as the Form closes to the same Close procedure.



However, the creation of a custom Close button is pointless if the closing X in the top right-hand corner of the Form remains active. To make the closing X inactive, open the Form Properties box then on the Format tab set the Close Button setting to No. This will grey out the closing X leaving it visible, but inactive.



View all Access hints and tips

Connect with us:

0207 987 3777

Call for assistance

Request Callback

We will call you back

Server loaded in 0.12 secs.