Forum Discussion
Calculating Conditional Running Totals
| Date | Name | Fruit | Quantity | Fruit Running Total |
| 1/1/2020 | Fred | Apple | 1 | 1 |
| 1/1/2020 | George | Orange | 1 | 1 |
| 1/2/2020 | Fred | Orange | 2 | 2 |
| 1/5/2020 | Fred | Orange | 5 | 7 |
| 1/7/2020 | George | Orange | 1 | 2 |
| 1/10/2020 | Fred | Apple | 3 | 4 |
Hi there and thank you for reading!
I am looking for a way to calculate conditional running totals. I am asking for help writing a formula that will calculate the 'Fruit Running Total' based on who the person is and what fruit they purchased on that date.
So for the above example,
- Fred gets 1 apple on the 1st, so his running total is 1. The next time he gets 3 apples on the 10th, so the running total should be 4.
- George gets 1 orange on the 1st, running total is 1 and the next time he gets an orange on the 7th, his running total should be 2.
- Fred gets 2 oragnes on the 2nd, running total is 2 and the next time he gets 5 oranges on the 5th, bringing his total to 7.
How would I calculate 'Fruit Running Total'?
Any help is appreciated!
Here you go bossamus
Full measure which returns the same as your expected result column in your sample data.
Running Total Measure = VAR varName = MAX('Table'[Name]) VAR varFruit = MAX('Table'[Fruit]) VAR varCurrentDate = MAX('Table'[Date]) VAR Result = SUMX( FILTER( ALL('Table'), 'Table'[Name] = varName && 'Table'[Fruit] = varFruit && 'Table'[Date] <= varCurrentDate ), 'Table'[Quantity] ) RETURN ResultHi bossamus ,
You may also create a column as below:
Fruit running total = SUMX(FILTER('Table','Table'[Fruit]=EARLIER('Table'[Fruit])&&'Table'[Name]=EARLIER('Table'[Name])&&'Table'[Date]<=EARLIER('Table'[Date])),'Table'[Quantity])And you will see:
For the related .pbix file,pls see attached.
Best Regards,
KellyDid I answer your question? Mark my post as a solution!
2 Replies
- edhansCommunity Champion
Here you go bossamus
Full measure which returns the same as your expected result column in your sample data.
Running Total Measure = VAR varName = MAX('Table'[Name]) VAR varFruit = MAX('Table'[Fruit]) VAR varCurrentDate = MAX('Table'[Date]) VAR Result = SUMX( FILTER( ALL('Table'), 'Table'[Name] = varName && 'Table'[Fruit] = varFruit && 'Table'[Date] <= varCurrentDate ), 'Table'[Quantity] ) RETURN Result - v-kelly-msftCommunity Support
Hi bossamus ,
You may also create a column as below:
Fruit running total = SUMX(FILTER('Table','Table'[Fruit]=EARLIER('Table'[Fruit])&&'Table'[Name]=EARLIER('Table'[Name])&&'Table'[Date]<=EARLIER('Table'[Date])),'Table'[Quantity])And you will see:
For the related .pbix file,pls see attached.
Best Regards,
KellyDid I answer your question? Mark my post as a solution!