Forum Discussion
Cumulative Total over a measure
- 8 years ago
Try this MEASURE in ITEMSTABLE
Revenue Cumulative = VAR CurrentRow = [Rank] RETURN SUMX ( FILTER ( ALLSELECTED ( ItemsTable[Item] ), [Rank] <= CurrentRow ), [Revenue] ) - 8 years ago
Thanks to Marco Russo I found a solution that avoid the uses of the VAR function!
https://www.sqlbi.com/blog/marco/2014/02/20/the-cumulative-total-dax-pattern/#comment-3722046622
Thanks everyone,
Angelo
Hi angelocecinati,
Can you share more detailed contents about your situation?
I'm not so sure how MG measure calculated, it will be help if you share measure formula and expected result.
Regards,
Xiaoxin Sheng
Hi Anonymous,
Sure! The MG measure is not so important. We can simplify further the example in this way:
| Item | Revenue | Rank | Revenue Cumulate |
| 101 | 100.000 | 1 | 100.000 |
| 103 | 80.000 | 2 | 180.000 |
| 102 | 50.000 | 3 | 230.000 |
| 105 | 10.000 | 4 | 240.000 |
I want to compute the Revenue Cumulate according to the Rank measure.
The Revenue is a measure coming directly from the cube. And I've not visibility about its computation.
The Rank is a measure computed as follow:
Rank = if (HASONEVALUE
(ItemsTable[Items])
,RANKX(ALL(ItemsTable[Items])
,[Revenue],,,Dense)
,BLANK()
)
The Revenue Cumulate has to show the highest revenue in the first row, the sum of the first and the second highest in the second row and so on.
I hope to be clear,
Thanks a lot,
Angelo
- Zubair_Muhammad8 years ago
Community Champion
Try this MEASURE in ITEMSTABLE
Revenue Cumulative = VAR CurrentRow = [Rank] RETURN SUMX ( FILTER ( ALLSELECTED ( ItemsTable[Item] ), [Rank] <= CurrentRow ), [Revenue] )- angelocecinati8 years agoFrequent Visitor
Hi Zubair_Muhammad,
Thanks a lot for your hint! I replicated it in the sample file and it works!
By the way if I recreate this measure on the SSAS cube .pbix it shows me an error on the var definition:It is due to the fact that the Rankx and the VAR functions are not accepted in direct query. I can rank directly using the revenue field. What about the VAR function use? Do you have any workaround?
Thanks Angelo
- angelocecinati8 years agoFrequent Visitor
Thanks to Marco Russo I found a solution that avoid the uses of the VAR function!
https://www.sqlbi.com/blog/marco/2014/02/20/the-cumulative-total-dax-pattern/#comment-3722046622
Thanks everyone,
Angelo
- jasonth328 years agoNew MemberThanks thats great! Excellent Solution!