Skip to main content
cancel
Showing results for 
Search instead for 
Did you mean: 

Power BI is turning 10! Let’s celebrate together with dataviz contests, interactive sessions, and giveaways. Register now.

Reply
Praveen806
New Member

Find out latitude and longitude from postal code

I am trying to populate latitude and longitude against a list of pincodes in excel. Trying with below code but giving error.

 

latlong is the name of table

pincode is the name of table header

 

let
Source = Excel.CurrentWorkbook(){[Name="latlong"]}[Content], 
#"Changed Type" = Table.TransformColumnTypes(Source,{{"pincode", type text}}),
#"Added Custom" = Table.AddColumn(#"Changed Type", "Custom", each Json.Document(Web.Contents("https://nominatim.openstreetmap.org/search?format=json&q=" & Text.From([pincode])))),
#"Expanded Custom" = Table.ExpandRecordColumn(#"Added Custom", "Custom", {"lat", "lon"}),
#"Changed Type1" = Table.TransformColumnTypes(#"Expanded Custom",{{"lat", type number}, {"lon", type number}})
in
#"Changed Type1"

1 REPLY 1
Sahir_Maharaj
Super User
Super User

Hello @Praveen806,

 

Can you please try this approach:

let
    Source = Excel.CurrentWorkbook(){[Name="latlong"]}[Content],
    #"Changed Type" = Table.TransformColumnTypes(Source,{{"pincode", type text}}),
    #"Added Custom" = Table.AddColumn(#"Changed Type", "Custom", each 
        let
            SourceJson = Json.Document(Web.Contents("https://nominatim.openstreetmap.org/search?format=json&q=" & [pincode])),
            FirstResult = if List.Count(SourceJson) > 0 then SourceJson{0} else null,
            
            Latitude = if FirstResult <> null then FirstResult[lat] else null,
            Longitude = if FirstResult <> null then FirstResult[lon] else null
        in
            [lat = Latitude, lon = Longitude]
    ),
    #"Expanded Custom" = Table.ExpandRecordColumn(#"Added Custom", "Custom", {"lat", "lon"}),
    #"Changed Type1" = Table.TransformColumnTypes(#"Expanded Custom",{{"lat", type number}, {"lon", type number}})
in
    #"Changed Type1"

Let me know if you might require any further assistance.


Did I answer your question? Mark my post as a solution, this will help others!

If my response(s) assisted you in any way, don't forget to drop me a "Kudos" 🙂

Kind Regards,
Sahir Maharaj
Data Scientist | Data Engineer | Data Analyst | AI Engineer
P.S. Want me to build your Power BI solution? (Yes, its FREE!)
➤ Lets connect on LinkedIn: Join my network of 15K+ professionals
➤ Join my free newsletter: Data Driven: From 0 to 100
➤ Website: https://sahirmaharaj.com
➤ Email: sahir@sahirmaharaj.com
➤ Want me to build your Power BI solution? Lets chat about how I can assist!
➤ Join my Medium community of 30K readers! Sharing my knowledge about data science and artificial intelligence
➤ Explore my latest project (350K+ views): Wordlit.net
➤ 100+ FREE Power BI Themes: Download Now
LinkedIn Top Voice in Artificial Intelligence, Data Science and Machine Learning

Helpful resources

Announcements
Join our Fabric User Panel

Join our Fabric User Panel

This is your chance to engage directly with the engineering team behind Fabric and Power BI. Share your experiences and shape the future.

June 2025 Power BI Update Carousel

Power BI Monthly Update - June 2025

Check out the June 2025 Power BI update to learn about new features.

June 2025 community update carousel

Fabric Community Update - June 2025

Find out what's new and trending in the Fabric community.

Top Solution Authors