Forum Discussion

itsmeanuj's avatar
itsmeanuj
Helper IV
2 years ago
Solved

Cumulative total while switching values

Hi Guys,

 

My Data looks like this and I need to show it in a matrix visual with a cumulative sum of values. Please note that there is a slicer filter at the top that switches the column values between Month_num and Month.

 

Input

CountryValueMonth_numMonth
US10011/1/2022
US12022/1/2022
US14033/1/2022
US11044/1/2022
US14555/1/2022
US18066/1/2022
US17077/1/2022
Germany14014/1/2022
Germany15025/1/2022
Germany16036/1/2022
Germany17047/1/2022
Germany18058/1/2022
Germany13069/1/2022
Germany140710/1/2022

 

Output 1 - Wheb Slicer value is selected as Month

Month1/1/20222/1/20223/1/20224/1/20225/1/20226/1/20227/1/20228/1/20229/1/202210/1/2022
US100220360470615795965   
Germany   1402904506208009301070

 

 

Output 2 - When the slicer value is selected as Month_num

Month_num1234567
US100220360470615795965
Germany1402904506208009301070

 

Can someone please help me to achieve this?

 

Thanks,
Anuj

  • Hi itsmeanuj 
    If I understood you correctly and you are working with the field parameters you can apple the following steps :
    1. Add to the field parameter column of the slicer's selections ( you will need it at the dax that will switch the formula according to your selection)

    2. Use this formula for the calculation of the running total :

    runming total =
    if(SELECTEDVALUE(Parameter[Month type])="month_num",
    CALCULATE(

                SUM('Table'[Value]),

                FILTER( ALLSELECTED('Table'[Month_num]),

              'Table'[Month_num]<= MAX(('Table'[Month_num]) )

                )),
                CALCULATE(

                SUM('Table'[Value]),

                FILTER( ALLSELECTED('Table'[Month]),

              'Table'[Month]<= MAX(('Table'[Month]) )

                ))

    )
    3. On the slicer, use the new column from step 1

    4. Create the matrix (parameter should be on columns)

    Result:

    PBIX is attached

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

  • Hi itsmeanuj 
    This logic will work for any date format according to your needs, everything is dynamic in my formulas.
    I changed your format just because my settings are dd/mm/yyyy , and I didn't want to reset them just for the sample solution 🙂

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

4 Replies

  • Hi itsmeanuj 
    If I understood you correctly and you are working with the field parameters you can apple the following steps :
    1. Add to the field parameter column of the slicer's selections ( you will need it at the dax that will switch the formula according to your selection)

    2. Use this formula for the calculation of the running total :

    runming total =
    if(SELECTEDVALUE(Parameter[Month type])="month_num",
    CALCULATE(

                SUM('Table'[Value]),

                FILTER( ALLSELECTED('Table'[Month_num]),

              'Table'[Month_num]<= MAX(('Table'[Month_num]) )

                )),
                CALCULATE(

                SUM('Table'[Value]),

                FILTER( ALLSELECTED('Table'[Month]),

              'Table'[Month]<= MAX(('Table'[Month]) )

                ))

    )
    3. On the slicer, use the new column from step 1

    4. Create the matrix (parameter should be on columns)

    Result:

    PBIX is attached

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

    • itsmeanuj's avatar
      itsmeanuj
      Helper IV

      Ritaf1983 - Thanks for your response on this. I realized that in the sample data, you have changed the dates of Germany. US data is from Jan-22 to July 22. Germany is from April 22 to Oct-22. In the actual data, there are a lot more countries with different starting dates. will this solution still work in that scenario?

      • Ritaf1983's avatar
        Ritaf1983
        Super User

        Hi itsmeanuj 
        This logic will work for any date format according to your needs, everything is dynamic in my formulas.
        I changed your format just because my settings are dd/mm/yyyy , and I didn't want to reset them just for the sample solution 🙂

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