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

Get inspired! Check out the entries from the Power BI DataViz World Championships preliminary rounds and give kudos to your favorites. View the vizzies.

Reply
Anonymous
Not applicable

Issue fetching paginated data from a REST API

Dear all,

i'm currently confronted with a pagination issue when getting data from a REST Apo.

 

When querying the REST API with a custom query i get the total of pages in return, but the query is repeating the data from the first page, and it doesn't return fetch the data from the others pages.

 

The custom query im using

 

let
BaseUrl = "--",
Token = "--",
EntitiesPerPage = 50,

GetJson = (Url) =>
let
Options = [Headers=[access_token="--", Accept="--", #"Content-Type"="--"]],
RawData = Web.Contents(BaseUrl, Options),
Json = Json.Document(RawData)
in Json,

GetEntityCount = () =>
let Url = BaseUrl & "$count=true&$top=0",
Json = GetJson(Url),
Count = Json[#"count"]
in Count,
GetPage = (Index) =>
let Skip = "$offset=" & Text.From(Index * EntitiesPerPage),
Url = BaseUrl & Skip,
Json = GetJson(Url),
Value = Json[#"items"]
in Value,

EntityCount = List.Max({ EntitiesPerPage, GetEntityCount() }),
PageCount = Number.RoundUp(EntityCount / EntitiesPerPage),
PageIndices = { 0 .. PageCount - 1 },
Pages = List.Transform(PageIndices, each GetPage(_)),
#"Converted to Table" = Table.FromList(Pages, Splitter.SplitByNothing(), null, null, ExtraValues.Error),
#"Expanded Column1" = Table.ExpandListColumn(#"Converted to Table", "Column1"),
#"Expanded Column2" = Table.ExpandRecordColumn(#"Expanded Column1", "Column1", {"href", "id", "firstName", "lastName"}, {"Column1.href", "Column1.id", "Column1.firstName"})
in
#"Expanded Column2"

 

I'm a newbie in Power Query so kindly ask your support & suggestions on how to resolve this issue.

 

 

1 REPLY 1
Greg_Deckler
Super User
Super User

@ImkeF @edhans 



Follow on LinkedIn
@ me in replies or I'll lose your thread!!!
Instead of a Kudo, please vote for this idea
Become an expert!: Enterprise DNA
External Tools: MSHGQM
YouTube Channel!: Microsoft Hates Greg
Latest book!:
Power BI Cookbook Third Edition (Color)

DAX is easy, CALCULATE makes DAX hard...

Helpful resources

Announcements
Las Vegas 2025

Join us at the Microsoft Fabric Community Conference

March 31 - April 2, 2025, in Las Vegas, Nevada. Use code FABINSIDER for a $400 discount!

FebPBI_Carousel

Power BI Monthly Update - February 2025

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

March2025 Carousel

Fabric Community Update - March 2025

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