Forum Discussion

bbrimberry's avatar
bbrimberry
New Member
5 years ago

Geocoding with power query in excel and bing

Hello fellow Excel lovers,


I am working on a custom power query function that will geocode addresses using bing maps. It works great with one exception. Bing is returning more than 1 match at times.

I only need 1 match. I'm not sure my URL is quite right.

Can someone advise?

 


let

 

findlatlong =(myLocation) =>

 

let

Source = Xml.Tables(Web.Contents(http://dev.virtualearth.net/REST/v1/Locations/&myLocation&"?o=xml&maxResults=1&key=mykey")),

#"Changed Type" = Table.TransformColumnTypes(Source,{{"Copyright", type text}, {"BrandLogoUri", type text}, {"StatusCode", Int64.Type}, {"StatusDescription", type text}, {"AuthenticationResultCode", type text}, {"TraceId", type text}}),

#"Removed Other Columns" = Table.SelectColumns(#"Changed Type",{"ResourceSets"}),

#"Expanded ResourceSets" = Table.ExpandTableColumn(#"Removed Other Columns", "ResourceSets", {"ResourceSet"}, {"ResourceSet"}),

ResourceSet = #"Expanded ResourceSets"{0}[ResourceSet],

#"Changed Type1" = Table.TransformColumnTypes(ResourceSet,{{"EstimatedTotal", Int64.Type}}),

Resources = #"Changed Type1"{0}[Resources],

#"Expanded Location" = Table.ExpandTableColumn(Resources, "Location", {"Confidence", "GeocodePoint"}, {"Confidence", "GeocodePoint"}),

#"Expanded GeocodePoint" = Table.ExpandTableColumn(#"Expanded Location", "GeocodePoint", {"Latitude", "Longitude", "UsageType"}, {"Latitude", "Longitude", "UsageType"}),

#"Removed Columns" = Table.RemoveColumns(#"Expanded GeocodePoint",{"UsageType"})

in

#"Removed Columns"

 

in findlatlong

 

1 Reply

  • You are already grabbing the first row    "{0}" in a couple places. Use the same approach where you encounter the issue.  Do you have a sample query that can reproduce the issue?