Forum Discussion
vajofr
9 years agoRegular Visitor
DAX - Reversed running total
Hi,
I'm trying to create the column in red "Remain Cap per Iteration" but I can't figure out how to do the calculation. I think I
need to use the CALCULATE formula together with SUM and EARLIER to get some kind of reversed running sum with subtotals that are grouped on the 'Iteration' and 'User' column but I can't get it to work.
| Date | Iteration | User | Capacity per User | Remain Cap per Iteration |
| 2017-06-08 | S1 | aa | 5 | 10 |
| 2017-06-09 | S1 | aa | 5 | 5 |
| 2017-06-10 | S1 | aa | 0 | 0 |
| 2017-06-11 | null | aa | 0 | 0 |
| 2017-06-12 | null | aa | 0 | 0 |
| 2017-06-13 | null | aa | 0 | 0 |
| 2017-06-08 | S1 | bb | 3 | 6 |
| 2017-06-09 | S1 | bb | 0 | 3 |
| 2017-06-10 | S1 | bb | 3 | 3 |
| 2017-06-11 | S2 | bb | 5 | 15 |
| 2017-06-12 | S2 | bb | 5 | 10 |
| 2017-06-13 | S2 | bb | 5 | 5 |
| 2017-06-08 | null | cc | 0 | 0 |
| 2017-06-09 | null | cc | 0 | 0 |
| 2017-06-10 | null | cc | 0 | 0 |
| 2017-06-11 | S2 | cc | 6 | 18 |
| 2017-06-12 | S2 | cc | 6 | 12 |
| 2017-06-13 | S2 | cc | 6 | 6 |
Any help is much appreciated.
Thanks!
Best,
Fredrik
In this scenario, you just need to use group total minus the cumulative total. You can create a measure like below:
Reverse Running Total = CALCULATE ( SUM ( Table2[Capacity per User] ), ALLEXCEPT ( Table2, Table2[User], Table2[Iteration] ) ) - CALCULATE ( SUM ( Table2[Capacity per User] ), ALLEXCEPT ( Table2, Table2[User], Table2[Iteration] ), FILTER ( ALLEXCEPT ( Table2, Table2[User], Table2[Iteration] ), Table2[Date] < MAX ( Table2[Date] ) ) )Regards,
1 Reply
- v-sihou-msftMicrosoft Employee
In this scenario, you just need to use group total minus the cumulative total. You can create a measure like below:
Reverse Running Total = CALCULATE ( SUM ( Table2[Capacity per User] ), ALLEXCEPT ( Table2, Table2[User], Table2[Iteration] ) ) - CALCULATE ( SUM ( Table2[Capacity per User] ), ALLEXCEPT ( Table2, Table2[User], Table2[Iteration] ), FILTER ( ALLEXCEPT ( Table2, Table2[User], Table2[Iteration] ), Table2[Date] < MAX ( Table2[Date] ) ) )Regards,