Forum Discussion

Spetter's avatar
Spetter
Advocate IV
8 years ago

Cumulative total

Hi,

 

I am making a cumulative percentage and I am using the DAX pattern to do this.

However, I need a slight customization. If I select Q2 I want the cumulative percentage to cumulate the percentage from Q3 and Q4 but my measure seems to cumulate also Q1 and Q2.

In the screenshot below I want to see 21,8% in Q3 in the dark column and 47,8% in Q4 in the dark column

 

Is there someone who can help me to fix this because I am not seeing what is going wrong?

 

My measure formula is as follows. I think the problem is in the blue part but I think I am really close, not sure though:

Cumulative percentage = 
DIVIDE(
IF(SELECTEDVALUE(Measuretable[Quarter])>SELECTEDVALUE(Disconnectedtable[Quarter]);
    CALCULATE(SUM(Measuretable[Actuals]);
        FILTER(ALL(Measuretable[Quarter]);Measuretable[Quarter]<=MAX(Measuretable[Quarter])))
);
    CALCULATE(SUM(Measuretable[Budget]);
ALL(Measuretable[Quarter])
)
)

 

Many thanks for all the help that can put me in the right direction!

 

Friendly greets

 

 

12 Replies

  • Hi,

     

    Your question is not clear.  What does the green column respresent?  When you select Q2, why should Q3 show 21.8%.  Please share a dataset and explain the business question.  Once we can compute the correct figures in a Table, creating a visual should be very simple.

    • Spetter's avatar
      Spetter
      Advocate IV

      Hi

       

      I have uploaded the file to

      https://www.dropbox.com/s/kgojyt35s0i97d1/test.pbix?dl=0

       

       

      Below you can see the datamodel and how I have used this in the dashboard

       

      The green bars is Percentage actuals (=Actuals/Budget). Budget is mapped to 01/01/20xx so when I want to calculate a quarterly % Actuals, I have to remove the filter on Quarter, else the budget will be 0 in Q2, Q3 and Q4

       

      Percentage actuals = 
      DIVIDE(
          SUM(Measuretable[Actuals]);
          CALCULATE(SUM(Measuretable[Budget]);ALL(Measuretable[Quarter]))
      )

       

      Percentage actuals cumulative from Qx is the same measure, but now I want it to be cumulative. The special requirement is:

      • that this measure can only be shown in the chart for the quarters after the selected quarter: this is what i did with the orange code below and with a disconnected table but maybe this can be improved? It is however amazing because Quarter is a textfield which contains Q1, Q2, Q3 and Q4. I don't even know how DAX knows how Q3 is greater than Q2 because it is text :) but it works!
      • that this measure can only cumulate the "Percentage actuals"for the quarters after the selected quarter. I didn't succeed to make this happen :s

       

      Percentage actuals cumulative from Qx = 
      DIVIDE(
          IF(SELECTEDVALUE(Measuretable[Quarter])>SELECTEDVALUE(Disconnectedtable[Quarter]);
              CALCULATE(
                  SUM(Measuretable[Actuals]);
                  FILTER(ALL(Measuretable[Quarter]);Measuretable[Quarter]<=MAX(Measuretable[Quarter])))
          );
          CALCULATE(
              SUM(Measuretable[Budget]);
              ALL(Measuretable[Quarter])
           )
       )

       

      In the chart below the endresult should be instead:

      • dark column Q3 = 22,2%
      • dark column Q4 = 22,2% + 30,5% = 52,7%

       

       

      The business question is actually something different. I need this technique to calculate a forecast. It is however pragmatic but maybe interesting to share :)

      • Forecast for Q3 will be the cumulative % from Q2 (= selected quarter) + the cumulative % from previous year starting from Q3 until Q3
      • Forecast for Q4 will be the cumulative % from Q2 (= selected quarter) + the cumulative % from previous year starting from Q3 until Q4

      What this will actual say is: when we use as much budget in Q3 and Q4 as previous year, we will go over budget (more than 100% in Q4) or we will still have enough budget.

       

      I hope this info can help to gain insight in the problem. I am happy to provide more info if I still didn't make this clear enough!

    • Spetter's avatar
      Spetter
      Advocate IV

      Hi

       

      I have uploaded the file to:

      https://www.dropbox.com/s/kgojyt35s0i97d1/test.pbix?dl=0

       

       

      Below you can see the datamodel and how I have used this in the dashboard

       

      The green bars is Percentage actuals (=Actuals/Budget). Budget is mapped to 01/01/20xx so when I want to calculate a quarterly % Actuals, I have to remove the filter on Quarter, else the budget will be 0 in Q2, Q3 and Q4

       

      Percentage actuals = 
      DIVIDE(
          SUM(Measuretable[Actuals]);
          CALCULATE(SUM(Measuretable[Budget]);ALL(Measuretable[Quarter]))
      )

       

      Percentage actuals cumulative from Qx is the same measure, but now I want it to be cumulative. The special requirement is:

      • that this measure can only be shown in the chart for the quarters after the selected quarter: this is what i did with the orange code below and with a disconnected table but maybe this can be improved? It is however amazing because Quarter is a textfield which contains Q1, Q2, Q3 and Q4. I don't even know how DAX knows how Q3 is greater than Q2 because it is text :) but it works!
      • that this measure can only cumulate the "Percentage actuals"for the quarters after the selected quarter. I didn't succeed to make this happen :s

       

      Percentage actuals cumulative from Qx = 
      DIVIDE(
          IF(SELECTEDVALUE(Measuretable[Quarter])>SELECTEDVALUE(Disconnectedtable[Quarter]);
              CALCULATE(
                  SUM(Measuretable[Actuals]);
                  FILTER(ALL(Measuretable[Quarter]);Measuretable[Quarter]<=MAX(Measuretable[Quarter])))
          );
          CALCULATE(
              SUM(Measuretable[Budget]);
              ALL(Measuretable[Quarter])
           )
       )

       

      In the chart below the endresult should be instead:

      • dark column Q3 = 22,2%
      • dark column Q4 = 22,2% + 30,5% = 52,7%

       

       

      The business question is actually something different. I need this technique to calculate a forecast. It is however pragmatic but maybe interesting to share :)

      • Forecast for Q3 will be the cumulative % from Q2 (= selected quarter) + the cumulative % from previous year starting from Q3 until Q3
      • Forecast for Q4 will be the cumulative % from Q2 (= selected quarter) + the cumulative % from previous year starting from Q3 until Q4

      What this will actual say is: when we use as much budget in Q3 and Q4 as previous year, we will go over budget (more than 100% in Q4) or we will still have enough budget.

       

      I hope this info can help to gain insight in the problem. I am happy to provide more info if necessary!

       

      Friendly greets

    • Spetter's avatar
      Spetter
      Advocate IV

      Hi

       

      I have uploaded the file to

      https://www.dropbox.com/s/kgojyt35s0i97d1/test.pbix?dl=0

       

       

      Below you can see the datamodel and how I have used this in the dashboard

       

       

      The green bars is Percentage actuals (=Actuals/Budget). Budget is mapped to 01/01/20xx so when I want to calculate a quarterly % Actuals, I have to remove the filter on Quarter, else the budget will be 0 in Q2, Q3 and Q4

       

      Percentage actuals =
      DIVIDE(
          SUM(Measuretable[Actuals]);
          CALCULATE(SUM(Measuretable[Budget]);ALL(Measuretable[Quarter]))
      )

       

      Percentage actuals cumulative from Qx is the same measure, but now I want it to be cumulative. The special requirement is:

      • that this measure can only be shown in the chart for the quarters after the selected quarter: this is what i did with the orange code below and with a disconnected table but maybe this can be improved? It is however amazing because Quarter is a textfield which contains Q1, Q2, Q3 and Q4. I don't even know how DAX knows how Q3 is greater than Q2 because it is text :) but it works!
      • that this measure can only cumulate the "Percentage actuals"for the quarters after the selected quarter. I didn't succeed to make this happen :s

       

      Percentage actuals cumulative from Qx = 
      DIVIDE(
          IF(SELECTEDVALUE(Measuretable[Quarter])>SELECTEDVALUE(Disconnectedtable[Quarter]);
              CALCULATE(
                  SUM(Measuretable[Actuals]);
                  FILTER(ALL(Measuretable[Quarter]);Measuretable[Quarter]<=MAX(Measuretable[Quarter])))
          );
          CALCULATE(
              SUM(Measuretable[Budget]);
              ALL(Measuretable[Quarter])
           )
       )

       

      In the chart below the endresult should be instead:

      • dark column Q3: 22,2%
      • dark column Q4: 22,2% + 30,5%: 52,7%

       

       

      The business question is actually something different. I need this technique to calculate a forecast. It is however pragmatic but maybe interesting to share

      • Forecast for Q3 will be the cumulative % from Q2 (= selected quarter) + the cumulative % from previous year starting from Q3 until Q3
      • Forecast for Q4 will be the cumulative % from Q2 (= selected quarter) + the cumulative % from previous year starting from Q3 until Q4

      What this will actual say is when we use as much budget in Q3 and Q4 as previous year, we will go over budget (more than 100% in Q4) or we will still have enough budget.

       

      I hope this info can help to gain insight in the problem. I am happy to answer more questions if necessary!

       

      Friendly greets

       

  • Any tips that can help me in the right direction?

     

    Friendly greets