Forum Discussion

rp2022's avatar
rp2022
Icon for Helper II rankHelper II
2 years ago
Solved

Running Total / Cummulative totals

Input: 

LabelDateMP$
PD3/2/20244406S7-100
PD3/3/20245102S7100
PD3/4/20246181S0200
PD3/5/20247161S0500
PD3/6/20247385S0-300
PD3/7/20249587S0200
ST3/8/20241000S7400
3/9/20243/9/20241001S7900
3/10/20243/10/20241201S7600
3/11/20243/11/20241201S7700
3/12/20243/12/20241201S7500
3/13/20243/13/20241201S7

-100

 

Output:

LabelDateMP$Running Total 
PD3/2/20244406S7-100-100=E2
PD3/3/20245102S71000=F2+E3
PD3/4/20246181S0200200=F3+E4
PD3/5/20247161S0500700=F4+E5
PD3/6/20247385S0-300400=F5+E6
PD3/7/20249587S0200600=F6+E7
ST3/8/20241000S7400400=E8
3/9/20243/9/20241001S7900900=E9
3/10/20243/10/20241201S76001500=F9+E10
3/11/20243/11/20241201S77002200=F10+E11
3/12/20243/12/20241201S75002700=F11+E12
3/13/20243/13/20241201S7-1002600=F12+E13

 Also, want to able to slice based on columns M, P, Label etc.

Apprciate any help

  • Anonymous's avatar
    Anonymous
    2 years ago

    Hi rp2022 ,

    Please create a new calculated column:

    Group = 
    VAR __cur_label = 'Table'[Label]
    VAR __group = IF(ISERROR(VALUE(__cur_label)),__cur_label,"Date")
    RETURN
    __group

    And then please create a new measure:

    Running Total = 
    VAR __group = MAX('Table'[Group])
    VAR __cur_date = MAX('Table'[Date])
    VAR __result = CALCULATE(SUM('Table'[$]),FILTER(ALLSELECTED('Table'),'Table'[Group]=__group && 'Table'[Date]<=__cur_date))
    RETURN
    __result

    Output:

    Best Regards,
    Gao

    Community Support Team

     

    If there is any post helps, then please consider Accept it as the solution  to help the other members find it more quickly.
    If I misunderstand your needs or you still have problems on it, please feel free to let us know. Thanks a lot!

    How to get your questions answered quickly --  How to provide sample data in the Power BI Forum -- China Power BI User Group

3 Replies

  • Anonymous's avatar
    Anonymous
    Not applicable

    Hi rp2022 ,

    Please create a new calculated column:

    Group = 
    VAR __cur_label = 'Table'[Label]
    VAR __group = IF(ISERROR(VALUE(__cur_label)),__cur_label,"Date")
    RETURN
    __group

    And then please create a new measure:

    Running Total = 
    VAR __group = MAX('Table'[Group])
    VAR __cur_date = MAX('Table'[Date])
    VAR __result = CALCULATE(SUM('Table'[$]),FILTER(ALLSELECTED('Table'),'Table'[Group]=__group && 'Table'[Date]<=__cur_date))
    RETURN
    __result

    Output:

    Best Regards,
    Gao

    Community Support Team

     

    If there is any post helps, then please consider Accept it as the solution  to help the other members find it more quickly.
    If I misunderstand your needs or you still have problems on it, please feel free to let us know. Thanks a lot!

    How to get your questions answered quickly --  How to provide sample data in the Power BI Forum -- China Power BI User Group

    • rp2022's avatar
      rp2022
      Icon for Helper II rankHelper II

      Works like a charm, thank you so much

  • Hi rp2022 
    You can use the DAX measure :

    Runing total =
     VAR MaxDate = MAX ( 'Table'[Date] ) -- Saves the last visible date
    RETURN
        CALCULATE (
            sum('Table'[$]),            -- Computes  sum of $
            'Table'[Date] <= MaxDate,   -- Where date is before the last visible date
            ALLSELECTED( ( 'Table'[Date] )               -- Removes any other filters from Date
        ))

    The pbix is attached

     If this post helps, then please consider Accepting it as the solution to help the other members find it more quickly