schwiggiddy
New Member
- Joined
- Sep 5, 2017
- Messages
- 31
I'm attempting to have PBI do some linear regression for me. From a helper query that iterates over multiple files, I'm calling this custom function to determine the highest reading above and lowest reading below the linear regression line over a variable length period for each row of data. It's working, but I'm getting an error on the service that says it cannot schedule a refresh because of (I think) the source of this query/function (it says Query1; I called this fnQuery1. The error is about a dynamic data source; this seems dynamic).
How would/could I go about integrating this function back into the helper query's main line of operations so as to eliminate the cause for the error? Two of the variables being passed to it are lists (reading and antiindex) and the other two are decimal numbers.
Have I overcomplicated the matter? Is there an easier way to do this that I've overlooked? Any help in the right direction would be most appreciated.
How would/could I go about integrating this function back into the helper query's main line of operations so as to eliminate the cause for the error? Two of the variables being passed to it are lists (reading and antiindex) and the other two are decimal numbers.
Have I overcomplicated the matter? Is there an easier way to do this that I've overlooked? Any help in the right direction would be most appreciated.
Power Query:
(reading as any, slopeb, intercepta, antiindex) =>
let
// Convert single values to single entry lists
listslopeb = {slopeb},
listintercepta = {intercepta},
// Combine 4 lists into a 4 column table
Source = Table.FromColumns({reading,listslopeb,listintercepta,antiindex},{"Reading", "Slopeb", "Intercepta", "AntiIndex"}),
// Fill the single value columns down to all rows
FillDown = Table.FillDown(Source, {"Slopeb", "Intercepta"}),
// Calculate the position of the linear regression line at each antiindex value
AddY = Table.AddColumn(FillDown, "YValue", each [Intercepta] + [AntiIndex] * [Slopeb]),
// Determine highest and lowest values from the linear regression line
SubtractReading = Table.AddColumn(AddY, "Delta", each [Reading] - [YValue]),
MaxDelta = Table.AddColumn(SubtractReading, "Max", each List.Max(SubtractReading[Delta])),
MinDelta = Table.AddColumn(MaxDelta, "Min", each List.Min(SubtractReading[Delta])),
// Return just a single row of data since the max and min are the same for each row
Return = Table.FirstN(MinDelta, 1)
in
Return