Forum Discussion
DAX year cummulative doesn't work with blank dates
Hi olijo
As a best practice, use a separate dates table with a complete rows of dates (no missing dates in between), relate it to your fact and apply the calculation on date column from the dates table and not on from fact. Please see attached sample pbix.
In SSAS Tabular, are you using a separate dates table? Those rows of dates must exist (whether with a value or not) for DATESYTD or any other time intelligence calculations to have a value for those otherwise they will just be skipped.
7 Replies
- olijoFrequent Visitor
Thanks, that obviously works in Power BI, but I am actually in SSAS tabular, using DAX, and there it doesn't work. Probably the definition of DATESYTD is different... I'll try some more...
- danextian
Super User
In SSAS Tabular, are you using a separate dates table? Those rows of dates must exist (whether with a value or not) for DATESYTD or any other time intelligence calculations to have a value for those otherwise they will just be skipped.
- rajendraongole1
Super User
Hi olijo -The issue here is that when there are missing dates (e.g., no data for June and December 2023), the DATESYTD function skips these months in the cumulative sum, resulting in gaps in your Year-To-Date (YTD) calculation.
use below calculation:
Cumulative YTD =
VAR CurrentDate = MAX('Data'[Date])
VAR CurrentYear = YEAR(CurrentDate)
RETURN
CALCULATE(
SUM('Data'[IZNOS7n]),
FILTER(
ALL('Data'),
YEAR('Data'[Date]) = CurrentYear &&
'Data'[Date] <= CurrentDate
)
)Hope it works.
- Angith_Nair
Continued Contributor
Hi olijo
Use the below DAX
CumulativeSumYTD = VAR CurrentYear = YEAR('Data'[Date]) RETURN CALCULATE( SUM('Data'[IZNOS7n]), FILTER( ALL('Data'), YEAR('Data'[Date]) = CurrentYear && 'Data'[Date] <= MAX('Data'[Date]) ) ) - Kedar_Pande
Super User
Make sure you have a Date table in your model with a continuous range of dates for all years (this includes months where no data is present in your Data table).
CumulativeSum =
VAR CurrentYear = YEAR(MAX('Data'[Date]))
RETURN
CALCULATE(
SUM('Data'[IZNOS7n]),
FILTER(
ALL('Date'),
'Date'[Date] <= MAX('Date'[Date]) &&
YEAR('Date'[Date]) = CurrentYear
)
)This adjusted measure should give you the correct cumulative sum
💌 If this helped, a Kudos 👍 or Solution mark would be great! 🎉
Cheers,
Kedar
Connect on LinkedIn - olijoFrequent Visitor
I've used seperate dates table, but in excel I didn't put date from that table, but from original table, stupid.
Thank you so much for your effort, you saved me!