1. Home
  2. Knowledge Base
  3. Tutorials
  4. How can I achieve pagination in Microsoft Power BI?
  1. Home
  2. Knowledge Base
  3. FAQs
  4. Data Analysis
  5. How can I achieve pagination in Microsoft Power BI?

How can I achieve pagination in Microsoft Power BI?

Here is a reference article to loop through OData Entities and retrieve all the records Power Query Rest API Paging with @odata.nextLink

In PowerBI, go to Transform Data โ†’ New Data Source โ†’ Blank query

Click Advanced Editor and paste the code in the black box below. Replace <Service link>/<Entity Name> with your Test or Production service links and Entity Name. Also, replace columnA, columnB, etc., with the attributes in your Entity.

When prompted for Credentials, select Basic Authentication and select the OutSystems username and password for the service link.

This will paginate in blocks of 1000, retrieve all the records in the Entity and add them to your Power BI model.

letย 
  ย  BaseUrl ย  ย  ย  ย  = "<Service link/<Entity Name>",
  ย  RecordsPerPage = 1000,
ย 
ย  ย  GetJson = (Url) =>
ย  ย  ย  ย  let Options = [
  ย  ย  ย  Headers = [#"accept" = "application/json"]
ย  ย  ย  ],
ย  ย  ย  ย  ย  ย  RawData = Web.Contents(Url, Options),
ย  ย  ย  ย  ย  ย  Json ย  ย = Json.Document(RawData)
ย  ย  ย  ย  in ย Json,
    
    GetTextData = (Url) =>
        let Options = [
        Headers = [#"accept" = "text/plain"]
    ],
        RawData = Web.Contents(Url, Options),
        TextData = Text.FromBinary(RawData)
    in TextData,
 
  ย  GetRecordCount = () =>
  ย  ย  ย  let Url ย  = BaseUrl & "/$count",
  ย  ย  ย  ย  ย  TextData ย = GetTextData(Url),
  ย  ย  ย  ย  ย  Count = Number.FromText(TextData)
ย  ย  ย  ย  in ย Count,
ย 
ย  ย  GetPage = (Index) =>
  ย  ย  ย  let Skip ย = "?$skip=" & Text.From(Index * RecordsPerPage),
  ย  ย  ย  ย  ย  Top ย  = "$top=" & Text.From(RecordsPerPage),
ย  ย  ย  ย  ย  ย  Url ย  = BaseUrl & Skip,
ย  ย  ย  ย  ย  ย  Json ย = GetJson(Url),
ย  ย  ย  ย  ย  ย  Value = Json[#"value"]
ย  ย  ย  ย  in ย Value,
ย 
  ย  RecordCount = List.Max({ RecordsPerPage, GetRecordCount() }),
  ย  PageCount ย  = Number.RoundUp(RecordCount / RecordsPerPage),
ย  ย  PageIndices = { 0 .. PageCount - 1 },
ย  ย  Pages ย  ย  ย  = List.Transform(PageIndices, each GetPage(_)),
  ย  Records ย  ย = List.Union(Pages),
  ย  Table ย  ย  ย  = Table.FromList(Records, Splitter.SplitByNothing(), null, null, ExtraValues.Error),
ย  ย  #"Expanded Column1" = Table.ExpandRecordColumn(Table, "Column1", {"columnA", "columnB", "columnC"})
in
  ย  #"Expanded Column1"

We recommend you assess the implementation of an incremental load approach for these big tables, and you can achieve this by using 1 of 2 ways I list below. You can even combine both for optimal result:

  • Delta sync – filtering by date range, to sync only records created or updated after the last sync.
    This article has detailed instructions on how to achieve this in Excel, but it’ll apply to PowerBI as well.

Optionally, we can increase the limit, in case you don’t see the need for the approaches above. From R2.3+ there’s a feature that allows you to customize this limit at a project level.

Was this article helpful?

Related Articles

Need Support?

Can't find the answer you're looking for?
Contact Support