Forum Discussion
Running Total for specific categories
Hi All,
I have specific needs to create a calculated Column for a running total based on Type and department.
Below is my sample data, and what I want to create is a "Calculated Column" on Running total.
| Date | Type | Department | Value | Running Total |
| 1/01/2021 | Actual | Sales | 1 | 1 |
| 1/01/2021 | Actual | HR | 2 | 2 |
| 1/01/2021 | Actual | Operation | 3 | 3 |
| 1/01/2021 | Actual | Purchasing | 4 | 4 |
| 1/01/2021 | Budget | Sales | 5 | 5 |
| 1/01/2021 | Budget | HR | 6 | 6 |
| 1/01/2021 | Budget | Operation | 7 | 7 |
| 1/01/2021 | Budget | Purchasing | 8 | 8 |
| 1/02/2021 | Actual | Sales | 9 | 10 |
| 1/02/2021 | Actual | HR | 10 | 12 |
| 1/02/2021 | Actual | Operation | 11 | 14 |
| 1/02/2021 | Actual | Purchasing | 12 | 16 |
| 1/02/2021 | Budget | Sales | 13 | 18 |
| 1/02/2021 | Budget | HR | 14 | 20 |
| 1/02/2021 | Budget | Operation | 15 | 22 |
| 1/02/2021 | Budget | Purchasing | 16 | 24 |
| 1/03/2021 | Actual | Sales | 17 | 27 |
| 1/03/2021 | Actual | HR | 18 | 30 |
| 1/03/2021 | Actual | Operation | 19 | 33 |
| 1/03/2021 | Actual | Purchasing | 20 | 36 |
| 1/03/2021 | Budget | Sales | 21 | 39 |
| 1/03/2021 | Budget | HR | 22 | 42 |
| 1/03/2021 | Budget | Operation | 23 | 45 |
| 1/03/2021 | Budget | Purchasing | 24 | 48 |
| 1/04/2021 | Actual | Sales | 25 | 52 |
| 1/04/2021 | Actual | HR | 26 | 56 |
| 1/04/2021 | Actual | Operation | 27 | 60 |
| 1/04/2021 | Actual | Purchasing | 28 | 64 |
| 1/04/2021 | Budget | Sales | 29 | 68 |
| 1/04/2021 | Budget | HR | 30 | 72 |
| 1/04/2021 | Budget | Operation | 31 | 76 |
| 1/04/2021 | Budget | Purchasing | 32 | 80 |
As an example, this is how the Actual - Sales Running Total is calculated:
| Date | Type | Department | Value | Running Total |
| 1/01/2021 | Actual | Sales | 1 | 1 |
| 1/02/2021 | Actual | Sales | 9 | 10 |
| 1/03/2021 | Actual | Sales | 17 | 27 |
| 1/04/2021 | Actual | Sales | 25 | 52 |
As an example, this is how the Budget - Sales Running Total is calculated:
| Date | Type | Department | Value | Running Total |
| 1/01/2021 | Budget | Sales | 5 | 5 |
| 1/02/2021 | Budget | Sales | 13 | 18 |
| 1/03/2021 | Budget | Sales | 21 | 39 |
| 1/04/2021 | Budget | Sales | 29 | 68 |
Can anyone please help?
TIA.
Cheers,
Kev
Hi, BigKev
Try to create a column like this:
Column = CALCULATE ( SUM ( 'Table'[Value] ), FILTER ( ALL ( 'Table' ), 'Table'[Department] = EARLIER ( 'Table'[Department] ) && 'Table'[Type] = EARLIER ( 'Table'[Type] ) && 'Table'[Date] <= EARLIER ( 'Table'[Date] ) ) )result:
Please refer to the attachment below for details
Hope this helps.
Best Regards,
Community Support Team _ Zeon Zheng
If this post helps, then please consider Accept it as the solution to help the other members find it more quickly.Hi,
This calculated column formula works
=CALCULATE(SUM(Data[Value]),FILTER(Data,Data[Type]=EARLIER(Data[Type])&&Data[Department]=EARLIER(Data[Department])&&Data[Date]<=EARLIER(Data[Date])))Hope this helps.
5 Replies
- amitchandakSuper User
BigKev , Try a meaure like
Sumx(filter(allselected(Table), table[Type] = max(Table[Type]) && Table[Date] = max(Table[Date])), Table[Value])
- BigKevHelper III
Hi Amit,
I need the solution for calculated column and not measure
Cheers,
Kev
- amitchandakSuper User
BigKev , replace Max -> earlier and remove allselected and try in column
This trick work, most of the time
Sumx(filter((Table), table[Type] = earlier (Table[Type]) && Table[Date] = earlier (Table[Date])), Table[Value])
- v-angzheng-msftCommunity Support
Hi, BigKev
Try to create a column like this:
Column = CALCULATE ( SUM ( 'Table'[Value] ), FILTER ( ALL ( 'Table' ), 'Table'[Department] = EARLIER ( 'Table'[Department] ) && 'Table'[Type] = EARLIER ( 'Table'[Type] ) && 'Table'[Date] <= EARLIER ( 'Table'[Date] ) ) )result:
Please refer to the attachment below for details
Hope this helps.
Best Regards,
Community Support Team _ Zeon Zheng
If this post helps, then please consider Accept it as the solution to help the other members find it more quickly. - Ashish_MathurSuper User
Hi,
This calculated column formula works
=CALCULATE(SUM(Data[Value]),FILTER(Data,Data[Type]=EARLIER(Data[Type])&&Data[Department]=EARLIER(Data[Department])&&Data[Date]<=EARLIER(Data[Date])))Hope this helps.