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

Register now to learn Fabric in free live sessions led by the best Microsoft experts. From Apr 16 to May 9, in English and Spanish.

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
Microsoft Fabric Learn Together

Microsoft Fabric Learn Together

Covering the world! 9:00-10:30 AM Sydney, 4:00-5:30 PM CET (Paris/Berlin), 7:00-8:30 PM Mexico City

PBI_APRIL_CAROUSEL1

Power BI Monthly Update - April 2024

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

April Fabric Community Update

Fabric Community Update - April 2024

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

Top Solution Authors