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

Register now to learn Fabric in free live sessions led by the best Microsoft experts. From Apr 16 to May 9, in English and Spanish.

Reply
monicamarrick
Regular Visitor

Geocoding function crashed when encountered error, how to skip error using DAX

I created a geocoding function through R script using Google API. The problem is when I geocoded the data in Power BI, the process stopped when encountered a bad address. How should I modify the DAX to solve this problem? I want Power BI to skip the error and continue to the next geocoding. Below is the geocoding function I created. 

 

 

let
    Source = (Parameter as text) => let
           Source = R.Execute("library(httr)#(lf)google_api <- ""https://maps.googleapis.com/maps/api/geocode/json""#(lf)geocode <- function(address, verbose=FALSE) {#(lf)r <- GET(google_api, query=list(address=address))#(lf)stop_for_status(r)#(lf)result <- content(r)#(lf)first <- result$results[[1]]#(lf)df <- as.data.frame(list(lat=first$geometry$location$lat, lon=first$geometry$location$lng))#(lf)return(df)#(lf)}#(lf)result <- geocode("""&Parameter&""")"),

 

         result1 = Source{[Name="result"]}[Value]

in
        result1
in
       Source

 

 

1 REPLY 1
Eric_Zhang
Employee
Employee


@monicamarrick wrote:

I created a geocoding function through R script using Google API. The problem is when I geocoded the data in Power BI, the process stopped when encountered a bad address. How should I modify the DAX to solve this problem? I want Power BI to skip the error and continue to the next geocoding. Below is the geocoding function I created. 

 

 

let
    Source = (Parameter as text) => let
           Source = R.Execute("library(httr)#(lf)google_api <- ""https://maps.googleapis.com/maps/api/geocode/json""#(lf)geocode <- function(address, verbose=FALSE) {#(lf)r <- GET(google_api, query=list(address=address))#(lf)stop_for_status(r)#(lf)result <- content(r)#(lf)first <- result$results[[1]]#(lf)df <- as.data.frame(list(lat=first$geometry$location$lat, lon=first$geometry$location$lng))#(lf)return(df)#(lf)}#(lf)result <- geocode("""&Parameter&""")"),

 

         result1 = Source{[Name="result"]}[Value]

in
        result1
in
       Source

 

 


@monicamarrick

Error-handling in Power Query may help, can you try and post the result?

Helpful resources

Announcements
Microsoft Fabric Learn Together

Microsoft Fabric Learn Together

Covering the world! 9:00-10:30 AM Sydney, 4:00-5:30 PM CET (Paris/Berlin), 7:00-8:30 PM Mexico City

PBI_APRIL_CAROUSEL1

Power BI Monthly Update - April 2024

Check out the April 2024 Power BI update to learn about new features.

April Fabric Community Update

Fabric Community Update - April 2024

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