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

Enhance your career with this limited time 50% discount on Fabric and Power BI exams. Ends September 15. Request your voucher.

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
August Power BI Update Carousel

Power BI Monthly Update - August 2025

Check out the August 2025 Power BI update to learn about new features.

August 2025 community update carousel

Fabric Community Update - August 2025

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

Top Solution Authors