Forum Discussion

Anonymous's avatar
Anonymous
Not applicable
3 years ago
Solved

Offset Pagination in Power Query

Hi!  I am trying to paginate my request which uses offset pagination. My response looks like this. The response.countEmail is the total number of items and I would like to set my limit to 100.  { ...
  • lbendlin's avatar
    3 years ago

    So you know your total count, and your desired return size. You don't need to worry about the previous limit.  Use a generator to craft all the URLs, then call all the URLs, then combine the results.

     

    Note that the list starts at 100 since you already fetched the entry at offset 0.

     

    let
        Source = Table.FromRows(Json.Document(Binary.Decompress(Binary.FromText("i45WsrQ0NjVTio0FAA==", BinaryEncoding.Base64), Compression.Deflate)), let _t = ((type nullable text) meta [Serialized.Text = true]) in type table [CountEmail = _t]),
        #"Changed Type" = Table.TransformColumnTypes(Source,{{"CountEmail", Int64.Type}}),
        #"Added Custom" = Table.AddColumn(#"Changed Type", "Custom", each let c = [CountEmail] in List.Generate(()=>100,each _ < c, each _+ 100)),
        #"Expanded Custom" = Table.ExpandListColumn(#"Added Custom", "Custom"),
        #"Added Custom1" = Table.AddColumn(#"Expanded Custom", "URL", each "https:///api.site.com?offset=" & Text.From([Custom]))
    in
        #"Added Custom1"

    How to use this code: Create a new Blank Query. Click on "Advanced Editor". Replace the code in the window with the code provided here. Click "Done".