Forum Discussion

Anonymous's avatar
Anonymous
Not applicable
5 years ago
Solved

Cumulative Sum

Morning,

 

I'm really struggling with creating a Cumulative total and not sure what I'm doing wrong. I've managed to create it previously but I couldn't get it to limit the values to this financial year (it was working the whole table) so I created a new table in DAX just bringing in the date periods I needed but now I can't get the running total to work.

Here's the code I'm using

Cumulative Sum =
     CALCULATE (
     sum(Sheet1[Budget]),
          FILTER (
          ALL ( Sheet1[Date].[Date]),
          Sheet1[Date].[Date] <= MAX (cummlative[Date].[Date] )
)
)


Hoping someone can help with the date limiting element or just get the above code working. I've tried to attach screenshots and a sample of the data, there's nothing special about it.
 
DateBudgetProjection
01-Feb-21194.37296.97
01-Feb-21146.2898.05
01-Feb-21707.1996.36
01-Feb-213683.071712.34
01-Feb-212034.122564.96
01-Mar-21110.37244.53
01-Mar-2134327.0211786.25
01-Mar-2115110.455989.95
01-Mar-2114410.224919.87
01-Mar-211223.431370.46
  • Hi, Anonymous 

    You can change the above measure like this:

    Cumulative Sum = 
    var _max = maxx(allselected(Cummlative),Cummlative[Date])
    return
    CALCULATE (
    sum(Sheet1[Budget]),
    FILTER (
    ALLselected ( Sheet1),
    Sheet1[Date] <= MAX (Sheet1[Date] )
    && Sheet1[Date] <=_max
    )
    )

    And you can get what you want, like this:

    You can download my test pbix file here

     

    If this result is not what you want, you can post some sample data(without sensitive data) and your expected result.

    How to Get Your Question Answered Quickly 

     

    Best Regards,

    Community Support Team _Robert Qin

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

3 Replies

  • Anonymous , Try a measure like


    Cumulative Sum =
    var _max = maxx(allselected(sheet,sheet[Date]))
    return
    if( CALCULATE (
    sum(Sheet1[Budget]),
    FILTER (
    ALLselected ( Sheet1),
    Sheet1[Date] <= MAX (Sheet1[Date] )
    && Sheet1[Date] <=_max
    )
    )

    • Anonymous's avatar
      Anonymous
      Not applicable

      Thanks for the quick reply on this,

      the MaxX is missing an expression - any ideas?

       

      Thanks.

      • v-robertq-msft's avatar
        v-robertq-msft
        Community Support

        Hi, Anonymous 

        You can change the above measure like this:

        Cumulative Sum = 
        var _max = maxx(allselected(Cummlative),Cummlative[Date])
        return
        CALCULATE (
        sum(Sheet1[Budget]),
        FILTER (
        ALLselected ( Sheet1),
        Sheet1[Date] <= MAX (Sheet1[Date] )
        && Sheet1[Date] <=_max
        )
        )

        And you can get what you want, like this:

        You can download my test pbix file here

         

        If this result is not what you want, you can post some sample data(without sensitive data) and your expected result.

        How to Get Your Question Answered Quickly 

         

        Best Regards,

        Community Support Team _Robert Qin

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