Forum Discussion
Issues with recuring API calls that use a dynamically generated cursor for fetching the next pages.
- 9 months ago
Hi ackerkris ,
Please refer below updated pagination logic, Please refer below snap and attached PBIX file.
I hope this information helps. Please do let us know if you have any further queries.
Regards,
Dinesh
Helloe v-dineshya ,
Apologies for the late reply, but too many unexpected things came popping up last Thursday & Friday and only now found some time to look into it.
I have created the following function:
GetData_Results_w_cursor_new
So far so good.
Next is a query calling upon that function:
Hi ackerkris ,
Thank you for the update. Please refer below optimized M code.
let
Source =
List.Generate(
() =>
[Result = #"GetData_Results_w_cursor_new"(2, "***", "0"), Cursor = "0"],
each [Cursor] <> null,
each
let
nextCursor = try [Result][SalaryCursor][next_cursor] otherwise null,
nextResult = if nextCursor <> null
then #"GetData_Results_w_cursor_new"(2, "***", nextCursor)
else null
in
[Result = nextResult, Cursor = nextCursor],
each
[
Salaries = try [Result][Value] otherwise null,
NextCursor = try [Result][SalaryCursor][next_cursor] otherwise null
]
),
PaginatedTable = Table.FromRecords(Source),
ExpandedSalaries = Table.ExpandListColumn(PaginatedTable, "Salaries"),
ExpandedAll =
let
firstRecord = try ExpandedSalaries[Salaries]{0} otherwise null,
fieldNames = if firstRecord <> null then Record.FieldNames(firstRecord) else {},
expanded = Table.ExpandRecordColumn(ExpandedSalaries, "Salaries", fieldNames, fieldNames)
in
expanded,
ExpandedValues = Table.ExpandListColumn(ExpandedAll, "values"),
ExpandedValuesDetails =
let
firstValue = try ExpandedValues[values]{0} otherwise null,
valueFields = if firstValue <> null then Record.FieldNames(firstValue) else {},
expanded = Table.ExpandRecordColumn(ExpandedValues, "values", valueFields, valueFields)
in
expanded,
ExpandedBase =
let
firstBase = try ExpandedValuesDetails[base]{0} otherwise null,
baseFields = if firstBase <> null then Record.FieldNames(firstBase) else {},
expanded = Table.ExpandRecordColumn(ExpandedValuesDetails, "base", baseFields, baseFields)
in
expanded
in
ExpandedBase
I hope this information helps. Please do let us know if you have any further queries.
Regards,
Dinesh