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

Enhance your career with this limited time 50% discount on Fabric and Power BI exams. Ends August 31st. Request your voucher.

Reply
ThePokyWizard
New Member

Pagination with dynamic pages

Recently, by following this tutorial, I managed to get PowerBI to generate a complete list with all the pages. The API I access works similarly to the one in the tutorial; however, it has parameters that list the most recent data. Thus, in one minute, I might have 5 pages, and in the next, I might have only 1 or even no results found.

 

In this model, a list is created with a fixed number of pages, but if I update the query, there may be no updated data, resulting in a 404 error when trying to navigate to a non-existent page, or even not navigating to the next page if it exceeds the original pages.

 

How can I create something more dynamic?

 

Additionally, the API I use returns an integer indicating the number of the next page, not just the total number of pages.

 

My JSON consists of this format:

 

 

 

/** Current Page 01 **/
{
	size: 1024,
	pages: 21,
	next_page: 2,
	previous_page: null,
	data: [
		{...},
		{...},
		{...},
		{...}
	]
}
/** Current Page 21 **/
{
	size: 1024,
	pages: 21,
	next_page: null,
	previous_page: null,
	data: [
		{...},
		{...},
		{...},
		{...}
	]
}

 

 

My URL follows this pattern:

https://example.com/api/?minutesSinceLastModification=15min&page=1
https://example.com/api/?minutesSinceLastModification=15min&page=2
https://example.com/api/?minutesSinceLastModification=15min&page=N
https://example.com/api/?minutesSinceLastModification=15min&page=1024
1 ACCEPTED SOLUTION
Sahir_Maharaj
Super User
Super User

Hello @ThePokyWizard,

 

Can you please try the following:

 

Function to Fetch Data

let
    FetchData = (page as number) as record =>
    let
        Source = Json.Document(Web.Contents("https://example.com/api/?minutesSinceLastModification=15min&page=" & Number.ToText(page))),
        Data = Source[data],
        NextPage = Source[next_page],
        Result = [Data = Data, NextPage = NextPage]
    in
        Result
in
    FetchData

Query to Fetch All Pages

let
    Source = (page as number) =>
    let
        Fetch = FetchData(page),
        Data = Fetch[Data],
        NextPage = Fetch[NextPage],
        GetAllData = if NextPage <> null then
                        Data & @Source(NextPage)
                     else
                        Data
    in
        GetAllData,

    // Start the pagination from page 1
    Data = Source(1)
in
    Data

Hope this helps.


Did I answer your question? Mark my post as a solution, this will help others!

If my response(s) assisted you in any way, don't forget to drop me a "Kudos" 🙂

Kind Regards,
Sahir Maharaj
Data Scientist | Data Engineer | Data Analyst | AI Engineer
P.S. Want me to build your Power BI solution? (Yes, its FREE!)
➤ Lets connect on LinkedIn: Join my network of 15K+ professionals
➤ Join my free newsletter: Data Driven: From 0 to 100
➤ Website: https://sahirmaharaj.com
➤ Email: sahir@sahirmaharaj.com
➤ Want me to build your Power BI solution? Lets chat about how I can assist!
➤ Join my Medium community of 30K readers! Sharing my knowledge about data science and artificial intelligence
➤ Explore my latest project (350K+ views): Wordlit.net
➤ 100+ FREE Power BI Themes: Download Now
LinkedIn Top Voice in Artificial Intelligence, Data Science and Machine Learning

View solution in original post

1 REPLY 1
Sahir_Maharaj
Super User
Super User

Hello @ThePokyWizard,

 

Can you please try the following:

 

Function to Fetch Data

let
    FetchData = (page as number) as record =>
    let
        Source = Json.Document(Web.Contents("https://example.com/api/?minutesSinceLastModification=15min&page=" & Number.ToText(page))),
        Data = Source[data],
        NextPage = Source[next_page],
        Result = [Data = Data, NextPage = NextPage]
    in
        Result
in
    FetchData

Query to Fetch All Pages

let
    Source = (page as number) =>
    let
        Fetch = FetchData(page),
        Data = Fetch[Data],
        NextPage = Fetch[NextPage],
        GetAllData = if NextPage <> null then
                        Data & @Source(NextPage)
                     else
                        Data
    in
        GetAllData,

    // Start the pagination from page 1
    Data = Source(1)
in
    Data

Hope this helps.


Did I answer your question? Mark my post as a solution, this will help others!

If my response(s) assisted you in any way, don't forget to drop me a "Kudos" 🙂

Kind Regards,
Sahir Maharaj
Data Scientist | Data Engineer | Data Analyst | AI Engineer
P.S. Want me to build your Power BI solution? (Yes, its FREE!)
➤ Lets connect on LinkedIn: Join my network of 15K+ professionals
➤ Join my free newsletter: Data Driven: From 0 to 100
➤ Website: https://sahirmaharaj.com
➤ Email: sahir@sahirmaharaj.com
➤ Want me to build your Power BI solution? Lets chat about how I can assist!
➤ Join my Medium community of 30K readers! Sharing my knowledge about data science and artificial intelligence
➤ Explore my latest project (350K+ views): Wordlit.net
➤ 100+ FREE Power BI Themes: Download Now
LinkedIn Top Voice in Artificial Intelligence, Data Science and Machine Learning

Helpful resources

Announcements
August Power BI Update Carousel

Power BI Monthly Update - August 2025

Check out the August 2025 Power BI update to learn about new features.

August 2025 community update carousel

Fabric Community Update - August 2025

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