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

Grow your Fabric skills and prepare for the DP-600 certification exam by completing the latest Microsoft Fabric challenge.

Reply
Gekko1
Helper I
Helper I

Loop through a paginated API getting the ID of the last record

My company is rebuilding our API's so they are paginated now. The problem is, one of our parameters should be the last ID of the record however, in order to get the loop working I should get the ID of the last record and use as the parameter of the next API query. The ID's arent sequential, so summing up a value to the ID's wont work. The thing is: I need a way to get the table last record ID, get back to power query with that ID and do that loop until the API return a empty table. The flow chart would be something like this:

First request without last ID record -----> Query returns a table with ID's -------> Get ID of the last record -------> Use this ID as a parameter for the next request



 

1 REPLY 1
ImkeF
Super User
Super User

Hi @Gekko1 ,
you can use the List.Generate function for it. In this blogpost I have shown a simple implementation for it:
How not to miss the last page when paging with Power BI and Power Query (thebiccountant.com)

Imke Feldmann (The BIccountant)

If you liked my solution, please give it a thumbs up. And if I did answer your question, please mark this post as a solution. Thanks!

How to integrate M-code into your solution -- How to get your questions answered quickly -- How to provide sample data -- Check out more PBI- learning resources here -- Performance Tipps for M-queries

Helpful resources

Announcements
RTI Forums Carousel3

New forum boards available in Real-Time Intelligence.

Ask questions in Eventhouse and KQL, Eventstream, and Reflex.

MayPowerBICarousel

Power BI Monthly Update - May 2024

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

Top Solution Authors
Top Kudoed Authors