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

Earn a 50% discount on the DP-600 certification exam by completing the Fabric 30 Days to Learn It challenge.

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
LearnSurvey

Fabric certifications survey

Certification feedback opportunity for the community.

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.