Skip to content
Clear Postcode

Integration · Spreadsheets

Postcode lookup in Excel

Excel's Power Query can call the API for every postcode in a table and add the council, ward, constituency and coordinates as new columns. Paste one query, refresh, done.

Get a free key10,000 lookups a month free · no card

Set it up

  1. 1Put your postcodes in a table with a column called Postcode.
  2. 2Data → Get Data → From Other Sources → Blank Query → Advanced Editor, paste the query, replace YOUR_KEY and the table name.
  3. 3Close & Load: the new columns appear. Data → Refresh All re-runs it.

The code

let
  Key = "YOUR_KEY",
  Source = Excel.CurrentWorkbook(){[Name="Table1"]}[Content],
  Look = (pc as text) => try Json.Document(Web.Contents("https://api.clearpostcode.co.uk/v1/postcodes/" & Uri.EscapeDataString(pc), [Headers=[#"x-api-key"=Key]]))[data] otherwise null,
  Added = Table.AddColumn(Source, "r", each Look([Postcode])),
  Out = Table.AddColumn(Table.AddColumn(Table.AddColumn(Added,
    "Council", each try [r][local_authority][name] otherwise null),
    "Ward", each try [r][ward][name] otherwise null),
    "Constituency", each try [r][constituency][name] otherwise null),
  Final = Table.RemoveColumns(Out, {"r"})
in
  Final