Weather station JSON
A JSON export of stations, each with a list of readings and optional flags. Flatten it to one row per reading without losing the station that has none.
intermediate · Skills: Json.Document, Expanding lists and records, Optional fields, Combining list values into text · Updated 2026-11-04
Data files
- stations.json — Three stations with nested location records and readings lists; one station has no readings and no location.Download JSON (1.7 KB)
Queries
Validated in the Power Query Exercises simulator against the files above. Paste them into Excel or Power BI yourself; the header comments explain each source binding.
One row per reading readings-flat.pq
Download .pqStation fields plus each reading; stations without readings stay with nulls. Returns 11 rows: StationID, Station, At, TempC, Humidity, Lat, Flags.
// One row per reading
// Pack: Weather station JSON (Power Query Exercises, https://powerqueryexercises.com/downloads/weather-station-json)
//
// Source bindings
// In the Power Query Exercises simulator each name below is bound directly to a pack file. In Excel or
// Power BI Desktop the first steps of this query do that binding instead:
// StationsJson the pack file stations.json -> File.Contents(PackFolder & "stations.json")
// Set PackFolder to the folder where you extracted the pack (keep the trailing backslash).
//
// Validated in the Power Query Exercises simulator (engine 0.1.0) against this pack's files; it returns
// 11 rows with columns StationID, Station, At, TempC, Humidity, Lat, Flags.
// It has not been run in Excel or Power BI by us. This is query text, not a ready-to-refresh workbook.
// Independent practice material; not affiliated with or endorsed by Microsoft.
let
PackFolder = "C:\PQE\weather-station-json\",
StationsJson = File.Contents(PackFolder & "stations.json"),
Source = Json.Document(StationsJson),
#"Stations" = Table.FromList(Source[stations], Splitter.SplitByNothing(), {"Station"}),
#"Station fields" = Table.ExpandRecordColumn(#"Stations", "Station", {"id", "name", "location", "readings"}, {"StationID", "Station", "location", "readings"}),
#"Latitude" = Table.AddColumn(#"Station fields", "Lat", each if [location] = null then null else [location][lat], type number),
#"One row per reading" = Table.ExpandListColumn(#"Latitude", "readings"),
#"Reading fields" = Table.AddColumn(#"One row per reading", "Flags", each if [readings] = null then null else Text.Combine(Record.FieldOrDefault([readings], "flags", {}), ", "), type text),
#"Expanded" = Table.ExpandRecordColumn(#"Reading fields", "readings", {"at", "tempC", "humidity"}, {"At", "TempC", "Humidity"}),
#"Removed" = Table.RemoveColumns(#"Expanded", {"location"})
in
#"Removed"
Follow along in a host
Follow along in Excel
- Download the pack and extract the zip, for example to C:\PQE\<pack name>\.
- In Excel (Microsoft 365 or 2016+ on Windows), go to Data → Get Data → From Other Sources → Blank Query.
- In the Power Query Editor choose Home → Advanced Editor, select everything and paste the contents of the .pq file.
- Change the PackFolder line to the folder you extracted to, then choose Done.
- If Excel asks about privacy levels or file access, allow access to that folder. Then choose Home → Close & Load.
Follow along in Power BI Desktop
- Download the pack and extract the zip.
- In Power BI Desktop choose Home → Transform data to open the Power Query Editor, then Home → New Source → Blank Query.
- Choose Home → Advanced Editor, paste the contents of the .pq file and change the PackFolder line to your folder.
- Choose Done, check the preview against the expected rows in the query header, then Close & Apply.
Then try this
- In the Power Query Editor, click a [List] or [Record] cell before expanding it to see what's inside.
- Add a new reading to stations.json with a flags list of two values and refresh: Flags shows both.
Related lessons
Original fictional data, free to use for learning and teaching. Power Query Exercises is not affiliated with or endorsed by Microsoft.