Power Query Call Function Stop

Tiger9136

New Member
Joined
Jul 10, 2017
Messages
19
Hello,

Here is what I have:

I am trying to pull records from a dynamic date range. Depending on the date parameters the records returned could be 100-25000. The API has a limit of 1000 records per call. I was able to make it this far and pull records but when there are no records to return it errors out the remaining tables. I know that if the records returned is less than 1000 then I have reached the end of the data pull.

Question #1: Source = #table({"Offset"}, {{0},{1000},{2000},{3000},{4000},{5000},{6000},{7000},{8000},{9000}}), Can this be modified so that it will continue to increment by 1000 until it the data returned is less than 1000?
Question#2: Stop the CallFunction when the last data pull was less then 1000.

Thanks for any help.


let
#"Code Blue 1" = let
//Table2
Source = #table({"Offset"}, {{0},{1000},{2000},{3000},{4000},{5000},{6000},{7000},{8000},{9000}}),
//CallFunction
CallFunction = Table.AddColumn(Source, "CallFunction", each try Function(Text.From([Offset]))),
//Function
Function = (Offset as text) =>
let
Source = Json.Document(Web.Contents("https://???-???.leading2lean.com/api/1.0/dispatches/?auth=xxxxxxxxxxxxxxxxxxxxxxxx" & "&dispatchtypecode=CodeRed" & "&reported__gte=" &CB1_Month("SpecifyDate","Begin")& "T00:00:00" & "&reported__lte=" &CB1_Month("SpecifyDate","End")& "T23:59:59" &"&limit=1000&offset="&Offset&"")),
data = Source[data],
#"Converted to Table" = Table.FromList(data, Splitter.SplitByNothing(), null, null, ExtraValues.Error),
#"Expanded Column1" = Table.ExpandRecordColumn(#"Converted to Table", "Column1", Record.FieldNames(#"Converted to Table"[Column1]{0}) )
in
#"Expanded Column1"
in
CallFunction,
 

Excel Facts

Shade all formula cells
To shade all formula cells: Home, Find & Select, Formulas to select all formulas. Then apply a light fill color.
Sorry, couldn’t edit original post.

Code:
let
#"Code Blue 1" = let
//Table2
Source = #table({"Offset"}, {{0},{1000},{2000},{3000},{4000},{5000},{6000},{7000},{8000},{9000}}),
//CallFunction
CallFunction = Table.AddColumn(Source, "CallFunction", each try Function(Text.From([Offset]))),
//Function
Function = (Offset as text) =>
let
Source = Json.Document(Web.Contents("https://???-???.leading2lean.com/api/1.0/dispatches/?auth=xxxxxxxxxxxxxxxxxxxxxxxx" & "&dispatchtypecode=CodeRed" & "&reported__gte=" &CB1_Month("SpecifyDate","Begin")& "T00:00:00" & "&reported__lte=" &CB1_Month("SpecifyDate","End")& "T23:59:59" &"&limit=1000&offset="&Offset&"")),
data = Source[data],
#"Converted to Table" = Table.FromList(data, Splitter.SplitByNothing(), null, null, ExtraValues.Error),
#"Expanded Column1" = Table.ExpandRecordColumn(#"Converted to Table", "Column1", Record.FieldNames(#"Converted to Table"[Column1]{0}) )
in
#"Expanded Column1"
in 
CallFunction,[CODE]
 
Upvote 0

Forum statistics

Threads
1,223,727
Messages
6,174,148
Members
452,547
Latest member
Schilling

We've detected that you are using an adblocker.

We have a great community of people providing Excel help here, but the hosting costs are enormous. You can help keep this site running by allowing ads on MrExcel.com.
Allow Ads at MrExcel

Which adblocker are you using?

Disable AdBlock

Follow these easy steps to disable AdBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the icon in the browser’s toolbar.
2)Click on the "Pause on this site" option.
Go back

Disable AdBlock Plus

Follow these easy steps to disable AdBlock Plus

1)Click on the icon in the browser’s toolbar.
2)Click on the toggle to disable it for "mrexcel.com".
Go back

Disable uBlock Origin

Follow these easy steps to disable uBlock Origin

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back

Disable uBlock

Follow these easy steps to disable uBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back
Back
Top