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

The Power BI Data Visualization World Championships is back! It's time to submit your entry. Live now!

Reply
StephenLis
Frequent Visitor

Another API pagination request for help!

Hi

I am using the Canvas LMS API and am struggling with a pagination issue. Using a few tutorials and posts from here I have managed to make some progress but haven’t quite nailed it.

Using the following query I am able to iterate through the pages of the endpoint I’m calling but the query loops endlessly.

 

 

 

let
    Query1 = List.Generate(()=>
[Result = try fComments(1) otherwise null, Page=1],
each [Result] <> null and [Page] < 10,
each [Result = try fComments([Page]+1) otherwise null, Page=[Page]+1],
each [Result])
in
    Query1

 

 

 

To stop this I added the [Page] < 10 condition and it now stops after 9 iterations and I can see the data I expect is being returned. Each call to the endpoint returns a list. The first few lists contain the data I want as expected but subsequent calls return empty lists. Whilst this is usable it is not ideal.

 

This is what is returned

lists.png

list1.png

Using Postman I can confirm that API calls to page numbers that don’t have data don’t return an error but rather return an empty list.

I need a way to add a condition that stops the loop when an empty list is returned but have not been able to work it out. Any help is appreciated.

Thanks

1 ACCEPTED SOLUTION
ppm1
Solution Sage
Solution Sage

Try changing your condition to the following. 

each List.Count([Result]) > 0 and [Page] < 10

 

Pat

 

Microsoft Employee

View solution in original post

2 REPLIES 2
StephenLis
Frequent Visitor

Thanks Pat

That worked, greatly appreciated

Cheers

ppm1
Solution Sage
Solution Sage

Try changing your condition to the following. 

each List.Count([Result]) > 0 and [Page] < 10

 

Pat

 

Microsoft Employee

Helpful resources

Announcements
FabCon Atlanta 2026 carousel

FabCon Atlanta 2026

Join us at FabCon Atlanta, March 16-20, for the ultimate Fabric, Power BI, AI and SQL community-led event. Save $200 with code FABCOMM.