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

Find everything you need to get certified on Fabric—skills challenges, live sessions, exam prep, role guidance, and more. Get started

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
Resolver III
Resolver III

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
Resolver III
Resolver III

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
Europe Fabric Conference

Europe’s largest Microsoft Fabric Community Conference

Join the community in Stockholm for expert Microsoft Fabric learning including a very exciting keynote from Arun Ulag, Corporate Vice President, Azure Data.

AugPowerBI_Carousel

Power BI Monthly Update - August 2024

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

August Carousel

Fabric Community Update - August 2024

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

Top Solution Authors
Top Kudoed Authors