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 All,
I'm fairly new to Power BI and Power Query, though I've been trying to reach myself how to use it in my free time. I've spent a considerable amount of time reading similar threads to this one and trying to apply the suggestions to my own project, but I've struggled to get my query fully working. I feel like this should be fairly simple based on other similar discussions, but was hoping for some assistance.
Background:
Current Query:
This is the current code:
let
Pagination = List.Skip(List.Generate(
() => [Last_Key = "init", Counter=0], // Start Value
each [Last_Key] <> null, // Condition under which the next execution will happen
each [ Last_Key = try if [Counter]<1 then "" else [WebCall][Value][page] otherwise null,// determine the LastKey for the next execution
WebCall = try if [Counter]<1 then Json.Document(Web.Contents("https://community.website.com/api/v2/users", [Headers=[Authorization="Bearer TOKEN"]])) else Json.Document(Web.Contents("https://community.website.com/api/v2/users/?page="&Last_Key&"", [Headers=[Authorization="Bearer TOKEN"]])), // retrieve results per call
Counter = [Counter]+1// internal counter
],
each [WebCall]
),1)
in
Pagination
Any help identifying the issue or suggesting an alternate approach would be appreciated. I've tried multiple forms of List.Generate and this was one of the few adaptations where I was able to return results without producing errors related to accessing list items, which I wasn't able to troubleshoot in earlier tries.
Thanks so much for any help in advance.
So your current query returns a list with just one row?
Then adjust the query like so and check the error-message that will be generated (then) for the 2nd item in the list:
let
Pagination = List.Skip(List.Generate(
() => [Last_Key = "init", Counter=0], // Start Value
each [Last_Key] <> null or [Counter] < 4, // Condition under which the next execution will happen
each [ Last_Key = try if [Counter]<1 then "" else [WebCall][Value][page] otherwise null,// determine the LastKey for the next execution
WebCall = try if [Counter]<1 then Json.Document(Web.Contents("https://community.website.com/api/v2/users", [Headers=[Authorization="Bearer TOKEN"]])) else Json.Document(Web.Contents("https://community.website.com/api/v2/users/?page="&Last_Key&"", [Headers=[Authorization="Bearer TOKEN"]])), // retrieve results per call
Counter = [Counter]+1// internal counter
],
each [WebCall]
),1)
in
Pagination
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
The Power BI Data Visualization World Championships is back! Get ahead of the game and start preparing now!
| User | Count |
|---|---|
| 19 | |
| 10 | |
| 9 | |
| 8 | |
| 7 |