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
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
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.