I am trying to delay a Power Query in Excel from running by about 25 seconds (Lets call it Query 2). This is to allow another query (Query 1) to pull data from an external source first. Query 2 only references internal table data and completes much faster than Query 1, meaning it misses most of the data updates. The result is I end up using "Refresh All" twice to pick up all the data. This is fine, but annoying and I believe can be solved by using the advanced editor in Power Query.
I can't use VBA code to resolve this for the particular spreadsheet (need to maintain .xlsx).
My research online has indicated that Function.InvokeAfter can be used to accomplish this.
I know you need to call all of the query actions as a function, but I'm having trouble with the syntax.
Here is my code snippet...it works, but does not delay the query as desired. I believe the problem is the way the Let command is processed (non sequentially). I'm sure the syntax is off as I'm a bit of a neophyte in the advanced editor in Power Query. Note I don't care about the getting time as text, I was just trying to do "something" to make the query delay. I've tried referencing the source line as the function but then I get an error about can't return a table as type function.
let
GetTimeAsText = ()=> DateTime.ToText(DateTime.LocalNow()),
Output = GetTimeAsText() & " " & Function.InvokeAfter(GetTimeAsText, #duration(0,0,0,25)),
Source = Excel.CurrentWorkbook(){[Name="ReviewHist"]}[Content],
#"Changed Type" = Table.TransformColumnTypes(Source,{{"Download Dt", type datetime}, {"LTCF", type text}, {"Other Monitored Settings", type text}}),
#"Appended Query" = Table.Combine({#"Changed Type", ReviewPrep}),
#"Changed Type1" = Table.TransformColumnTypes(#"Appended Query",{{"Download Dt", type date}}),
#"Removed Duplicates" = Table.Distinct(#"Changed Type1", {"Download Dt"}),
#"Sorted Rows" = Table.Sort(#"Removed Duplicates",{{"Download Dt", Order.Descending}})
in
#"Sorted Rows"