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

Don't miss out! 2025 Microsoft Fabric Community Conference, March 31 - April 2, Las Vegas, Nevada. Use code MSCUST for a $150 discount. Prices go up February 11th. Register now.

Reply
SCurtis
New Member

Looping through a list using Power Query M

Hello, 
 
I am trying to make a series of calles to a particular API endpoint and pass it a different variable with each call. Once we receive and parse the response from the API, we need to insert a related variable as a custom column.
 
I have set up a separate Query using the direct entry of data that contains both of these variables. I am looking for a simple way to repeat the request for each entry in the table. Code and table are both included below. I've tried to make it obvious where each field goes. 
 
What's the easiest way to do this?
 
Query ParkBranchMatrix Table
BranchIDParkCode
123456Example1
456789Example2
147258Example3
 
Query GetEmails M Code
let
    // Define the endpoint
    url = API_Endpoint,
 
    // Define the JSON body
    jsonBody = Text.ToBinary("{ ""network"": { ""network_id"": "& Network_ID &" }, ""branch"": { ""branch_id"": [===BranchID Goes Here===] } }"),
    
  #"Added custom" = Table.AddColumn(expandedUserInformation, "Park Code", each "[===ParkCode Goes Here===]"),
1 ACCEPTED SOLUTION
Chewdata
Super User
Super User

Hey,

 

Maybe you can turn the query into a function.

 

func_GetEmails

(vBranchID as text, vParkCode as text) =>

let

...

 

 

Then call the function by adding a column

 

Table.AddColumn(PreviousStep, "getEmails", each func_GetEmails([BranchID], [ParkCode]))

 

Make the function return a nested table/record, which then can expand.

 

 

 

View solution in original post

1 REPLY 1
Chewdata
Super User
Super User

Hey,

 

Maybe you can turn the query into a function.

 

func_GetEmails

(vBranchID as text, vParkCode as text) =>

let

...

 

 

Then call the function by adding a column

 

Table.AddColumn(PreviousStep, "getEmails", each func_GetEmails([BranchID], [ParkCode]))

 

Make the function return a nested table/record, which then can expand.

 

 

 

Helpful resources

Announcements
Las Vegas 2025

Join us at the Microsoft Fabric Community Conference

March 31 - April 2, 2025, in Las Vegas, Nevada. Use code MSCUST for a $150 discount!

Jan25PBI_Carousel

Power BI Monthly Update - January 2025

Check out the January 2025 Power BI update to learn about new features in Reporting, Modeling, and Data Connectivity.

Jan NL Carousel

Fabric Community Update - January 2025

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

Top Solution Authors