Forum Discussion
TOTALYTD until TODAY
- 9 years ago
Anonymous
Just clarifying your requirements...
If today is 5-Sep-2017, then what date range do you expect the formula to calculate over?
- 1-Jan-2017 to 5-Sep-2017 (cumulative total as at today, but with years ending on 31-Dec)
- 6-Sep-2016 to 5-Sep-2017 (cumulative total as at today, and with years ending on today's date, which would be the same as summing the last year ending today)
- Something else?
As a side note, in the TOTALYTD or DATESYTD functions, year_end_date can never be any expression apart from a string literal. If you want a flexible year_end_date, you have to write the time intelligence logic from scratch without using the built-in time intelligence functions.
Owen :)
- Anonymous9 years ago
From your insight, I came to this scratch formula that seems to work for me.
Thank you!
YTD Values = var ActualMonthBeginning = DATE(YEAR(TODAY());MONTH(TODAY());01) var YearBeginning = DATE(YEAR(MIN(Dates[dates]));01;01) return CALCULATE([Total Values] ;FILTER(Values ;Values[Dates] < ActualMonthBeginning && Values[Dates] >= YearBeginning ) )
Anonymous
That's good if the formula gives the desired result!
I would just propose this simper alternative:
Given that your year_end_date is the default of 31-Dec, and you are simply calculating a cumulative total as at "today", you can get away with a simpler formula.
Also, it would be best practice to apply date filters only to the Dates table. I am assuming there is a relationship between Values[Dates] and Dates[dates].
YTD Values =
CALCULATE (
TOTALYTD ( [Total Values]; Dates[dates] );
TREATAS ( { TODAY () }; Dates[dates] )
)
You should only need to write YTD time intelligence logic if you have a 'flexible' year-end date, but in your case it is just the date filter that needs to be flexible (set equal to TODAY()).
Owen :)