Forum Discussion

ompowerbi's avatar
ompowerbi
Icon for Helper I rankHelper I
3 years ago
Solved

Running Total for each Group / ID

Hi, I am trying to create a running total in my table that only does the running total for each respective Group / ID. An example of my table is below.  ID Number Date Apple 20 01/01/2023 ...
  • Vijay_A_Verma's avatar
    3 years ago

    Use this. Replace ??? appropriately

    let
        Source = ???
        BuffNumberList = Source[Number],
        BuffIDList = Source[ID],
        GenListOfRunningTotal = List.Generate(()=>[x=BuffNumberList{0},y=0], each [y]<List.Count(BuffNumberList), each [y=[y]+1, x=if BuffIDList{y} = BuffIDList{[y]} then [x]+BuffNumberList{y} else BuffNumberList{y}], each [x]),
        Result = Table.FromColumns(Table.ToColumns(Source) & {GenListOfRunningTotal},Table.ColumnNames(Source)&{"Running total per group"})
        in
        Result