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

The Power BI Data Visualization World Championships is back! Get ahead of the game and start preparing now! Learn more

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
Microsoft Employee
Microsoft 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
Power BI DataViz World Championships

Power BI Dataviz World Championships

The Power BI Data Visualization World Championships is back! Get ahead of the game and start preparing now!

December 2025 Power BI Update Carousel

Power BI Monthly Update - December 2025

Check out the December 2025 Power BI Holiday Recap!

FabCon Atlanta 2026 carousel

FabCon Atlanta 2026

Join us at FabCon Atlanta, March 16-20, for the ultimate Fabric, Power BI, AI and SQL community-led event. Save $200 with code FABCOMM.