I'm trying to create a new column from one of the records in a List type column. The value is the country that corresponds with the Latitude and Longitude fields. The information is retrieved from the Bing Map API, which got using Get Data from Web (following the tutorial here: https://sqldusty.com/2016/04/26/power-bi-and-the-bing-maps-api/).
Basically I need List.Record[1].address.countryRegion. Is it possible to make a column that holds this specific value without doing "Expand to new rows"? The issue is that some of the columns come back with France, and the number of rows increases to over 1000 but there should only be around 250.
Here is how I got to the point of having the column of Lists:
1. Get data from the web
2. Used Basic option and pasted working API request for a location with my bing maps key. Then click ok.
http://dev.virtualearth.net/REST/v1/Locations/point=40,-122?&key=BingMapsKey
3. Navigated to the Advanced editor in View > Advanced editor.
4. Made a function that uses Latitude and Longitude as input
let getCountry = (Latitude as text, Longitude as text) =>
let
Source = Json.Document(Web.Contents("http://dev.virtualearth.net/REST/v1/Locations/point="& Latitude &","& Longitude &"?&key=BingMapsKey"))
in
Source
in
getCountry
5. Renamed the function to GetCountry, then navigated to the desired table to add the column to (with Latitude and Longitude)
6. In the target table, Navigate to Add Column > Invoke Custom Function
7. Chose GetCountry from the list of functions, changed the type to column name and assigned the inputs to respective column names (latitude and longitude). Then clicked OK.
8. The column shows up on the right. I filtered out all columns besides 'resourceSets' because that has the address values.
EDIT I found a way to reduce the number of lists that are returned in the request, which is to only request the Country/Region as a query parameter:
http://dev.virtualearth.net/REST/v1/Locations/40,-122?key=BingMapsKey&includeEntityTypes=CountryRegion
This works for my needs for now, but maybe it's a good idea to keep this open to see if someone knows how to make a table from the nested table values? Thanks for all your help!