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

The ultimate Microsoft Fabric, Power BI, Azure AI & SQL learning event! Join us in Las Vegas from March 26-28, 2024. Use code MSCUST for a $100 discount. Register Now

Reply
FoxEddy
Frequent Visitor

How to get this pagination code work?

Hi there,

 

The following code always returned duplicated records of the ones on the 1st page. For example, there's 155 pages of data, the data on the 1st page gets duplicated 155 times, while no data from 2nd page onward is there. Can someone please help? Thanks a lot.

 

***

 

 

    // Define page size
    pageSize = 500,
    currentPage = 1,

    // funtion to get 1 page of data
    GetVulnerabilitiesPage = (page) =>
        let
            // API call URL
            url = apiUrl & "?page=" & Text.From(page) & "&per_page=" & Text.From(pageSize),

            // Send API call
            source = Json.Document(Web.Contents(url, [Headers=[#"X-Risk-Token"=apiKey]])),

            // Pull data
            vulnerabilities = source[vulnerabilities]
        in
            vulnerabilities,

    // Get total records
    GetEntityCount = () =>
        let
            //API call URL
            url = apiUrl & "?page=1" & "&per_page=" & Text.From(pageSize),

            // API call
            source = Json.Document(Web.Contents(url, [Headers=[#"X-Risk-Token"=apiKey]])),

            // Record number
            value = source[meta][total_count]
        in
            value,

    // Total page count (-150 below is for quick debug purpose, to get less results.)
    VulnCount = GetEntityCount(),
    totalPages = Number.RoundUp(VulnCount / pageSize) - 150,

    // Get all records
    allVulnerabilities = List.Generate(
        () => [Page = 1, Data = GetVulnerabilitiesPage(1)],
        each [Page] <= totalPages,
        each [
            Page = _[Page] + 1, 
            Data = GetVulnerabilitiesPage([Page])
            ],
        each _[Data]

 

 

1 ACCEPTED SOLUTION
lbendlin
Super User
Super User
1 REPLY 1
lbendlin
Super User
Super User

Helpful resources

Announcements
Fabric Community Conference

Microsoft Fabric Community Conference

Join us at our first-ever Microsoft Fabric Community Conference, March 26-28, 2024 in Las Vegas with 100+ sessions by community experts and Microsoft engineering.

February 2024 Update Carousel

Power BI Monthly Update - February 2024

Check out the February 2024 Power BI update to learn about new features.

Fabric Career Hub

Microsoft Fabric Career Hub

Explore career paths and learn resources in Fabric.

Fabric Partner Community

Microsoft Fabric Partner Community

Engage with the Fabric engineering team, hear of product updates, business opportunities, and resources in the Fabric Partner Community.