Forum Discussion

Anonymous's avatar
Anonymous
Not applicable
4 years ago
Solved

Cumulative sum based on multiple slicers

Hello!

I am trying to figure out how to calculate a cummulative total of a column based on multiple slicers.

 

My data looks like the following:

FundTypeDateValue
1A12/21/2021100
1B3/15/2022150
1A4/16/202250
2B11/14/2021200
2B1/16/2022150
2A2/16/2022200
3B1/15/202150
3A10/8/2021300
3B3/18/2022150

 

 

So, if I were to set the slicers to Fund: 1 & 2, Type: A and Date<=2/18/22, I need a function to show me the total cummulative value of those selections. I bolded the values that would be summed together. So the cumm. value would be the following:

FundTypeDateValueCumm Value
1A12/21/2021100300
1B3/15/2022150300
1A4/16/202250300
2B11/14/2021200300
2B1/16/2022150300
2A2/16/2022200300
3B1/15/202150300
3A10/8/2021300300
3B3/18/2022150300

 

I have tried the following for Cumm. Value but it doesn't work when I have when I slice on both Fund and Type

 

 

Cumm Value = 
    CALCULATE(
        SUM('Data'[Value]),
        FILTER(
            'Data',
            'Data'[Fund]=EARLIER('Data'[Fund]) 
            && 'Data'[Type]=EARLIER('Data'[Type]) 
            && 'Data'[Date] <= EARLIER('Data'[Date])
            )
            )

 

 

Any suggestions will be greatly appreciated. Thanks!

 

  • Anonymous's avatar
    Anonymous
    4 years ago

    Hi  Anonymous ,

    Here are the steps you can follow:

    1. Create calculated table.

    Date = CALENDAR(MIN('Table'[Date]),MAX('Table'[Date]) )

    Fund_select =
    DISTINCT('Table'[Fund])

    Type_select =
    DISTINCT('Table'[Type])

    2. Create measure.

    Measure =
    var _Fund=SELECTCOLUMNS('Fund_select',"1",[Fund])
    var _selectType=SELECTEDVALUE('Type_select'[Type])
    var _selectdate=SELECTEDVALUE('Date'[Date])
    return
    CALCULATE(
        SUM('Table'[Value]),
        FILTER(ALL( 'Table'),
        'Table'[Fund] in _Fund &&'Table'[Date]<=_selectdate&&'Table'[Type]=_selectType))
    

    3. Result:

    Use [Date] of table Date, [Fund] of table Fund_select, and [Type] of table Type_select as slicers respectively.

     

    Best Regards,

    Liu Yang

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

2 Replies

  • Anonymous's avatar
    Anonymous
    Not applicable

    Hi  Anonymous ,

    Here are the steps you can follow:

    1. Create calculated table.

    Date = CALENDAR(MIN('Table'[Date]),MAX('Table'[Date]) )

    Fund_select =
    DISTINCT('Table'[Fund])

    Type_select =
    DISTINCT('Table'[Type])

    2. Create measure.

    Measure =
    var _Fund=SELECTCOLUMNS('Fund_select',"1",[Fund])
    var _selectType=SELECTEDVALUE('Type_select'[Type])
    var _selectdate=SELECTEDVALUE('Date'[Date])
    return
    CALCULATE(
        SUM('Table'[Value]),
        FILTER(ALL( 'Table'),
        'Table'[Fund] in _Fund &&'Table'[Date]<=_selectdate&&'Table'[Type]=_selectType))
    

    3. Result:

    Use [Date] of table Date, [Fund] of table Fund_select, and [Type] of table Type_select as slicers respectively.

     

    Best Regards,

    Liu Yang

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