This time we’re going bigger than ever. Fabric, Power BI, SQL, AI and more. We're covering it all. You won't want to miss it.
Learn moreLevel up your Power BI skills this month - build one visual each week and tell better stories with data! Get started
Hi everyone,
I've been reading up on the advice for looping through a paginated API as a source (great resources here, here and here).
I have a slightly different case which I'm trying to deal with where the API I'm using will paginate to infinity producing tables with just the column headers and no data. So the error checking is not kicking in because the pages do have a table, and the looping continues for ever!
So what I need is a check to say that if the number of rows in the table is 1 (just the headers) then stop the looping.
The function i'm using is:
= (page as number) as table =>
let
Source = Web.Page(Web.Contents("https://api.xxxx.com&max-results=10000&page-num=" & Number.ToText(page) & "&apikey=12345")),
Source1 = Source{0}[Data]
in
Source1And the table source is:
= List.Generate( () => [Page Number =1,Func=null], each (try _[Func])[HasError]=false, each [Page Number=_[Page Number]+1, Func=GetData([Page Number]+1)], each _[Func])
I've looked at using Count.Rows but I'm not sure how to build it into this. Any ideas greatfully received!
Solved! Go to Solution.
Just change the condition accordingly.
each [Page Number] = 0 or
My solution:
Function "Get JSON" (which actually returns a list)
let
Source = (page as number) as list =>
let
URL = Text.Combine({
"https://some.url&page=",
Number.ToText(page)
}),
Response = Web.Contents(
URL
),
Source = Json.Document(Response)
in
Source
in
SourceQuery
let
Source = List.Combine(
List.Generate(
() => [page = 1, Func=#"Get JSON"(1)], // initial
each List.Count([Func]) > 0, // condition
each [
page = [page]+1,
Func = #"Get JSON"([page])
], // next
each [Func] // selector
)
),
#"Converted to Table" = Table.FromList(Source, Splitter.SplitByNothing(), null, null, ExtraValues.Error),
in
#"Converted to Table"It starts calling the "Get JSON" function starting with page=1 and going as long as the function returns at least 1 item.
You may use the following condition to replace the try expression.
each [Page Number] = 1 or Table.RowCount([Func]) > 1,
Hi @v-chuncz-msft,
Many thanks for taking the time to respond 🙂
I modified the code to:
= List.Generate( () => [Page Number=0, Func=null], each [Page Number] = 1 or Table.RowCount([Func]) > 1, each [Page Number=_[Page Number]+1, Func=GetData([Page Number]+1)], each _[Func])
But it gives me the error message:
Expression.Error: We cannot convert the value null to type Table.
Details:
Value=
Type=Type
If I try changing the line to say...
() => [Page Number=0, Func=1],
...then I still get the same message.
Any additional thoughts? Many thanks for your advice.
Just change the condition accordingly.
each [Page Number] = 0 or
Ah so obvious! 🙂
Thank you for your help.
Any chance you can please provide the full code? (without the actual API). Having the same challenge as well.
Thanks
Hi
Any chance you can provide all the code? I'm having the same challenge as well just now.
Check out the April 2026 Power BI update to learn about new features.
Sign up to receive a private message when registration opens and key events begin.
If you have recently started exploring Fabric, we'd love to hear how it's going. Your feedback can help with product improvements.
| User | Count |
|---|---|
| 30 | |
| 23 | |
| 21 | |
| 18 | |
| 17 |
| User | Count |
|---|---|
| 63 | |
| 35 | |
| 34 | |
| 24 | |
| 23 |