Forum Discussion
TOTALYTD until TODAY
Dear all,
I´m trying a "simple" measure to calculate the cumulative values from the beginning of the year until "today".
The formula below works, but notice I´m fixing the "year_end_date"
YTD Values =
TOTALYTD([Total Values];Dates[Dates];ALL(Dates[Dates]);"9/5")
However, if I try to set up "9/5" as a formula, like "TODAY()", or other vars, it gives me an error.
YTD Values =
var Today = MONTH(TODAY()) & "/" & DAY(TODAY())
return
TOTALYTD([Total Values];Dates[Dates];ALL(Dates[Dates]);Today)
Help? :smileyhappy:
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 ) )
16 Replies
- bsas
Post Patron
Hi,
I think the problem is that TOTALYTD do not see your var today as date. Try to use full date (e.g. 2/5/2017).
- AnonymousNot applicable
bsas wrote:Hi,
I think the problem is that TOTALYTD do not see your var today as date. Try to use full date (e.g. 2/5/2017).
Thank you for the reply, Bsas,
However, it didn´t work. I tried both adding "TODAY()" to end of the formula, also adding "var Today = TODAY()", and also setting DATE(2017,9,5), but I get an error message saying:
"True/false expression does not specify a column. Each expression in a True/False expression that is used as a table filter expression"
- OwenAuger
Super User
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 :)
- AnonymousNot applicable
Owen,
Thanks for the reply.
If today is 5-Sep-2017, I´d like 1-Jan-2017 to 5-Sep-2017, and so on, until 31-Dec.
In this case, I guess TOTALYTD, as you mentioned, won´t work for me, right?
OwenAuger wrote: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 :)
- AnonymousNot applicable
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 ) )
- AnonymousNot applicable
I use the IF(MAX function to get blanks after today
YTD Values = IF(MAX('Dates'[Date]) > TODAY() , BLANK(), CALCULATE(TOTALYTD([Total Values], 'Dates'[Date])))