Forum Discussion
running total DAX
I have related tables - Debt_table ,Calendar
Debt table columns:
Date | Client | Sell/Payment
I calculate running total , to know clients debt balance to date.
Total Debt = CALCULATE([Total Sell/Payment],FILTER(ALL(Debt_table),Debt_table[Date]<=MAX(Debt_table[Date])))
I make Pivot table
Date | Total Debt - it show good numbers. When i add Client filter context i get nonsense. How to force respect Client filter ?
Data sample:
| Client | Date | Sell/Payment |
| 0001 | 2005-04-04 | -141.19 |
| 0212 | 2005-04-06 | 310.68 |
| 0212 | 2005-04-06 | 503.48 |
| 0001 | 2005-04-06 | 138.58 |
| 0212 | 2005-04-08 | -1.39 |
| 0212 | 2005-04-08 | 1.39 |
| 0212 | 2005-04-08 | -7.82 |
| 0212 | 2005-04-08 | 7.82 |
| 0001 | 2005-04-12 | 73.42 |
| 0001 | 2005-04-13 | -175.08 |
| 0212 | 2005-04-14 | 444.16 |
| 0212 | 2005-04-14 | 149.96 |
| 0212 | 2005-04-19 | -109.79 |
| 0212 | 2005-04-19 | -20.77 |
| 0212 | 2005-04-19 | 730.68 |
| 0001 | 2005-04-19 | 141.19 |
| 0212 | 2005-04-20 | 124.4 |
| 0001 | 2005-04-25 | 135.54 |
| 0212 | 2005-04-26 | 655.93 |
| 0212 | 2005-04-26 | 786.39 |
| 0212 | 2005-05-03 | 978.67 |
| 0212 | 2005-05-05 | 482.5 |
| 0212 | 2005-05-06 | 155.89 |
| 0001 | 2005-05-09 | -138.58 |
| 0001 | 2005-05-09 | -248.49 |
Without Client Running total works fine:
| YYYY-MM | Total Sell/Payment | Running Total |
| 2005-04 | 3748 | 3748 |
| 2005-05 | 3945 | 7693 |
| 2005-06 | 2300 | 9993 |
| 2005-07 | 2914 | 12907 |
| Grand Total | 12907 | 12907 |
Adding a Client and something goes wrong.
| YYYY-MM | Client | Total Sell/Payment | Running Total |
| 2005-04 | 0212 | 3575 | 3748 |
| 2005-05 | 0212 | 4219 | 7518 |
| 2005-06 | 0212 | 2105 | 9993 |
| 2005-07 | 0212 | 3188 | 12907 |
| Grand Total | 13088 | 12907 |
Solution is to run FILTER against Calendar table , not Debt_table.
CALCULATE([Total Sell/Payment],FILTER(ALL('Calendar'[Date]),'Calendar'[Date]<=MAX('Calendar'[Date])))
9 Replies
- BILASolutionSolution Specialist
Hi vejas
Try this...
1. The next picture shows the sample data... (Table1)
2. I created a calculated column with the next DAX...
Accumulative Payment = var cli = Table1[Client] var dat = Table1[Date] return CALCULATE(SUM(Table1[Payment]);CALCULATETABLE(ALL(Table1);Table1[Client] = cli);Table1[Date] <= dat ; Table1[Client] = cli)
3. I created the next measures with DAX...
Total Payment = SUM(Table1[Payment])
Total Accumulative Payment = SUM(Table1[Accumulative Payment])
4. The final report looks like this...( after hiding useless columns)
Regards
BILASolution
- Ashish_MathurSuper User
Hi vejas,
Try this
=CALCULATE([Total Sell/Payment],FILTER(ALL(Debt_table[Date]),Debt_table[Date]<=MAX(Debt_table[Date])))
Hope this helps.
- vejasHelper I
This is not working. (Debt_table[Date]) dont work even without Client.
Thanks
- Ashish_MathurSuper User
Hi,
Share the link from where i can download your file.