Forum Discussion

Anonymous's avatar
Anonymous
Not applicable
5 years ago
Solved

Calculating value differences for last 7 days for each element of the columns

Hi everyone!   I wanted to ask for a help with a right way of constructing a loop inside the Power Query function.   I have a table of date, index and multiple value columns like below with thous...
  • Smauro's avatar
    5 years ago

    Hi Anonymous 

     

    You could try adding this using the Advanced Editor:

     

        Data = Table.Buffer(Table.AddKey(LastStep, {"Index"}, true)),

        AddLast = Table.AddColumn(
            Data, "Previous Day Diff",
            each let i = [Index] - 1 in Number.Abs( Data{[Index = i]}?[Value1]? - [Value1] )??0,
            type number ),
        AddLast7Check = Table.AddColumn(
            AddLast, "Last 7<5",
            each List.Max(List.Transform({[Index]-6..[Index]-1},
               (n) => AddLast{[Index = n]}?[Previous Day Diff]?) & {[Previous Day Diff]}) < 5,
            type logical)
    in
        AddLast7Check

     

    Replacing LastStep with your last step's name.

    Cheers