Forum Discussion
Cumulative (Running) Totals in DAX
- Anonymous10 years ago
Give the following a try:
Cumulative Sales:=IF(MIN(DimDate[Datekey])<=CALCULATE(MAX(FactSales[DateKey]),ALL(FactSales)),CALCULATE([Total Sales],FILTER(All(DimDate[Datekey]),DimDate[Datekey]<=MAX((DimDate[Datekey])))),BLANK())
Please mark it as a solution or give a kudo if it works for you, otherwise let me know if you run into an issue and I'll do my best to assist.
Thanks,
Do you have an alternative solution instead of using IF ( COUNTROWS(FactSales) > 0? Lets say you drill down to day level and some days don't have any rows in your fact then a value will not be calculated for these days.
IF (
COUNTROWS ( FactSales ) > 0,
...
...
...
BLANK()
)
Give the following a try:
Cumulative Sales:=IF(MIN(DimDate[Datekey])<=CALCULATE(MAX(FactSales[DateKey]),ALL(FactSales)),CALCULATE([Total Sales],FILTER(All(DimDate[Datekey]),DimDate[Datekey]<=MAX((DimDate[Datekey])))),BLANK())
Please mark it as a solution or give a kudo if it works for you, otherwise let me know if you run into an issue and I'll do my best to assist.
Thanks,
- Anonymous9 years agoNot applicable
This suggestion has gotten me closer. Thank you!
Instead of Blank() I used 0, however, since it's a cumulative count I'm going for, I'm thinking instead of zero I would actually need the value show before. So that 0 plus the last value. Any ideas on getting that for the true part of this IF statement?
Cumulative Sales (Correct) :=
IF (
COUNTROWS ( FactSales ) > 0,
CALCULATE (
[Total Sales],
FILTER (
ALL ( DimDate[Datekey] ),
DimDate[Datekey] <= MAX ( ( DimDate[Datekey] ) )
)
),
BLANK ()
)