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

Join us for an expert-led overview of the tools and concepts you'll need to become a Certified Power BI Data Analyst and pass exam PL-300. 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
Join our Fabric User Panel

Join our Fabric User Panel

This is your chance to engage directly with the engineering team behind Fabric and Power BI. Share your experiences and shape the future.

June 2025 Power BI Update Carousel

Power BI Monthly Update - June 2025

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

June 2025 community update carousel

Fabric Community Update - June 2025

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