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

Get certified in Microsoft Fabric—for free! For a limited time, get a free DP-600 exam voucher to use by the end of 2024. Register now

Reply
ToluO
New Member

Loop within a loop - API query

Hi,

 

I would like create a loop within a loop using the Power Query advanced editor.

 

I want to loop through all group Ids in a list, then for each group id, loop through the pages returned in the API reponse and add this to a table. Any clue on how to do this? Thanks 

 

Below is the code that I currently have which only supports pagination so far.

PBI - Loop within a loop help.JPG

let
group_ids = "X", "Y", "Z"
base_url = "https://devcloud.net",
getPage = (page_number) =>
let
relativeurl = "/api/v4/groups/" & group_id & "/epics?per_page=100&page=" & Text.From(page_number),
url = "https://devcloud.ubs.net",
headers = [
Authorization = "Bearer Token"
],
response = Json.Document(Web.Contents(url, [RelativePath=relativeurl, Headers=headers])),
issues = response
in
issues,
iteratePages = List.Generate(
() => 1,
each let currentPage = _,
currentPageData = getPage(currentPage)
in
currentPageData <> {},
each _ + 1,
each getPage(_)
),

2 REPLIES 2
Omid_Motamedise
Memorable Member
Memorable Member

To run loop in Power Query the following videos of mine can help you


For next loop by List.Accumulate

 

https://youtu.be/G8PRbWuDcmQ?si=1ij5Jo7kg1RboWgz

 

Do-while loop by List.Generate

https://youtu.be/iDYCtvTWFvY?si=piTHDUHGDnbt1kqU

 

 

but I think your problem might be solved by List.Transfrom also, so if you couldnt find the solution after whatching the videos, please provide sample of your question and result table then I can help you over your data

lbendlin
Super User
Super User

Please provide a more detailed explanation of what you are aiming to achieve. What have you tried and where are you stuck?


As you can probably appreciate it is nearly impossible to help with API queries without access to said API  (which you may not be willing to provide for understandable reasons)

Helpful resources

Announcements
November Carousel

Fabric Community Update - November 2024

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

Live Sessions with Fabric DB

Be one of the first to start using Fabric Databases

Starting December 3, join live sessions with database experts and the Fabric product team to learn just how easy it is to get started.

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! Early Bird pricing ends December 9th.

Nov PBI Update Carousel

Power BI Monthly Update - November 2024

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