Forum Discussion
dokat
Post Prodigy
4 years agoDateadd function returning error
Hi, I am trying to create a calculate dcolumn using values in Calender Year Column. To calculate YTDLY i am using below dateadd function line but it returns following error. Can anyone have solve...
- 4 years ago
PhilipTreacy Please disregard my questions. I modified the code and below worked for me.
Slicer = var maxdate = calculate(max(CY[Calendar Year]),all())return switch(true(), CY[Calendar Year]= maxdate,"YTD", CY[Calendar Year]= maxdate-365,"YTDLY", CY[Calendar Year]= DATE ( YEAR (maxdate)-1, 12, 31 ),"Last Year", CY[Calendar Year]= DATE ( YEAR (maxdate)-2, 12, 31 ),"Last YearLY", and(MONTH(CY[Calendar Year]) = month(maxdate),YEAR(CY[Calendar Year]) = YEAR(maxdate)),"Last Month", and(MONTH(CY[Calendar Year]) = month(maxdate),YEAR(CY[Calendar Year]) = Year(maxdate)-1),"Last MonthLY")
PhilipTreacy
Super User
4 years agoHi dokat
I'm a bit unclear about the code you've written, it's always best to supply the file you are using, but, when you declare a VAR you don't subsequently reference it using the VAR keyword. You also need to supply a default return value for SWITCH. Try this
Slicer =
VAR maxdate = calculate(max(CY[Calendar Year]),all())
RETURN SWITCH( TRUE(),
CY[Calendar Year]= maxdate,"YTD",
CY[Calendar Year] = dateadd(maxdate, -1,year),"YTDLY",
"DEFAULT VALUE"
)
regards
Phil
- dokat4 years ago
Post Prodigy
PhilipTreacy Thanks for your response. still receiving below error message
The first argument to 'DATEADD' must specify a column.
Below line worked for me
CY[Calendar Year]= maxdate-365,"YTDLY".