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

Join the FabCon + SQLCon recap series. Up next: Power BI, Real-Time Intelligence, IQ and AI, and Data Factory take center stage. All sessions are available on-demand after the live show. Register now

Reply
pbi_user2024
Regular Visitor

How to call WEB API iteratively using values from Excel or power Query column

Hi,

Trying to get distance between 2 points, either Zipcodes or Latitude/Logitude. Got the API key for Google Distance matrix API. Works fine when I manually try. But I have an Excel file in which I have columns with Zip codes for from and To and I want to iteratively go thru that list and get the distance and add in a new column. Either in excel or on Power Query.

 

For e,g, I tried below in a browser and got the distance.


https://maps.googleapis.com/maps/api/distancematrix/json
?destinations=22434
&origins=23173
&units=imperial
&key= XXXX

 

Anyone has any ideas ? A step by step guide will be very helpful.

Thanks in advance.

Ann

1 ACCEPTED SOLUTION
johnbasha33
Super User
Super User

@pbi_user2024 

Hi try the below.
=Json.Document(Web.Contents("https://maps.googleapis.com/maps/api/distancematrix/json?origins=" & Text.From([FromZip]) & "&destinations=" & Text.From([ToZip]) & "&units=imperial&key=YOUR_API_KEY"))[rows]{0}[elements]{0}[distance][text]

  1. Open your Excel file containing the columns with zip codes for "from" and "to".
  2. Go to the "Data" tab and click on "From Table/Range" to import the data into Power Query.
  3. In the Power Query Editor, select the columns containing the "from" and "to" zip codes.
  4. Go to the "Add Column" tab and click on "Custom Column".
  5. In the "Custom Column" dialog box, enter a name for the new column (e.g., "Distance").
  6. In the custom column formula, construct the URL to call the Google Distance Matrix API. You can use the Text.From function to convert the zip codes to text and concatenate them into the URL. Here's an example formula:
    Did I answer your question? Mark my post as a solution! Appreciate your Kudos !!

View solution in original post

1 REPLY 1
johnbasha33
Super User
Super User

@pbi_user2024 

Hi try the below.
=Json.Document(Web.Contents("https://maps.googleapis.com/maps/api/distancematrix/json?origins=" & Text.From([FromZip]) & "&destinations=" & Text.From([ToZip]) & "&units=imperial&key=YOUR_API_KEY"))[rows]{0}[elements]{0}[distance][text]

  1. Open your Excel file containing the columns with zip codes for "from" and "to".
  2. Go to the "Data" tab and click on "From Table/Range" to import the data into Power Query.
  3. In the Power Query Editor, select the columns containing the "from" and "to" zip codes.
  4. Go to the "Add Column" tab and click on "Custom Column".
  5. In the "Custom Column" dialog box, enter a name for the new column (e.g., "Distance").
  6. In the custom column formula, construct the URL to call the Google Distance Matrix API. You can use the Text.From function to convert the zip codes to text and concatenate them into the URL. Here's an example formula:
    Did I answer your question? Mark my post as a solution! Appreciate your Kudos !!

Helpful resources

Announcements
April Power BI Update Carousel

Power BI Monthly Update - April 2026

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

New to Fabric survey Carousel

New to Fabric Survey

If you have recently started exploring Fabric, we'd love to hear how it's going. Your feedback can help with product improvements.

Power BI DataViz World Championships carousel

Power BI DataViz World Championships - June 2026

A new Power BI DataViz World Championship is coming this June! Don't miss out on submitting your entry.

FabCon and SQLCon Highlights Carousel

FabCon &SQLCon Highlights

Experience the highlights from FabCon & SQLCon, available live and on-demand starting April 14th.