Join us at FabCon Atlanta from March 16 - 20, 2026, for the ultimate Fabric, Power BI, AI and SQL community-led event. Save $200 with code FABCOMM.
Register now!The Power BI Data Visualization World Championships is back! Get ahead of the game and start preparing now! Learn more
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
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
Solved! Go to Solution.
Try changing your condition to the following.
each List.Count([Result]) > 0 and [Page] < 10
Pat
Thanks Pat
That worked, greatly appreciated
Cheers
Try changing your condition to the following.
each List.Count([Result]) > 0 and [Page] < 10
Pat
The Power BI Data Visualization World Championships is back! Get ahead of the game and start preparing now!
| User | Count |
|---|---|
| 17 | |
| 9 | |
| 9 | |
| 7 | |
| 7 |