Register now to learn Fabric in free live sessions led by the best Microsoft experts. From Apr 16 to May 9, in English and Spanish.
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 for this problem?
"The syntax for ',' is incorrect. (DAX(var maxdate = calculate(max(CY[Calendar Year]),all())return switch(true(), CY[Calendar Year]= maxdate,"YTD",CY[Calendar Year]= dateadd(var maxdate, -1,year),"YTDLY")))."
Slicer = var maxdate = calculate(max(CY[Calendar Year]),all())return switch(true(),
CY[Calendar Year]= maxdate,"YTD",
CY[Calendar Year]= dateadd(var maxdate, -1,year),"YTDLY")
Solved! Go to Solution.
@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")
Please supply your file otherwise we have to recreate everything by hand.
regards
Phil
Proud to be a Super User!
@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")
Hi @dokat
Is there a reason the "ALL" function does not have a table or column name (just before the RETURN in your first line of code)?
Cheers,
Theo
If I have posted a response that resolves your question, please accept it as a solution to formally close the post.
Also, if you are as passionate about Power BI, DAX and data as I am, please feel free to reach out if you have any questions, queries, or if you simply want to connect and talk to another data geek!
Want to connect?www.linkedin.com/in/theoconias
@TheoC I modified the code slightly and it worked FOR ytdly however now I can't figure out Last MonthLY value. Please see below screenshot. I am trying to 01/01/2021 should be Last MonthLY
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)-12,YEAR(CY[Calendar Year]) = YEAR(maxdate)),"Last MonthLY")
I am trying to get the max date based on selection of slicers thats wy there is not table for all.
Hi @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
Proud to be a Super User!
@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"
.
Covering the world! 9:00-10:30 AM Sydney, 4:00-5:30 PM CET (Paris/Berlin), 7:00-8:30 PM Mexico City
Check out the April 2024 Power BI update to learn about new features.
User | Count |
---|---|
111 | |
97 | |
82 | |
67 | |
61 |
User | Count |
---|---|
150 | |
120 | |
99 | |
87 | |
68 |