Forum Discussion
If else then Otherwise in calculated column
- 8 years ago
Hi Anonymous,
From your screenshot, you created a custom column in Query Editor rather than creating a calculated colunmn using DAX formula. And your date column should be Date type date, while you type the Yesterday and Current Date(they are text date), so it returns error because date equals text type(like 2018/1/22=Current Date).
I create a sample table. Today is 2018/1/22.
In Query Editor, I click the yesterday and today in Calendar(highlighted in red circle), it will return correct result.
add conditionresult
If you want to create a calculated column using DAX instead of Query statement, you can create it using the formula.Calculated column = IF ( Table1[Date] = TODAY (), "Current Date", IF ( Table1[Date] = DATE ( YEAR ( TODAY () ), MONTH ( TODAY () ), DAY ( TODAY () ) - 1 ), "Yesterday", "Other Day" ) )
Please see the result as follows.
Best Regards,
Angelia
Hi Anonymous,
From your screenshot, you created a custom column in Query Editor rather than creating a calculated colunmn using DAX formula. And your date column should be Date type date, while you type the Yesterday and Current Date(they are text date), so it returns error because date equals text type(like 2018/1/22=Current Date).
I create a sample table. Today is 2018/1/22.
In Query Editor, I click the yesterday and today in Calendar(highlighted in red circle), it will return correct result.
add conditionresult
If you want to create a calculated column using DAX instead of Query statement, you can create it using the formula.
Calculated column =
IF (
Table1[Date] = TODAY (),
"Current Date",
IF (
Table1[Date]
= DATE ( YEAR ( TODAY () ), MONTH ( TODAY () ), DAY ( TODAY () ) - 1 ),
"Yesterday",
"Other Day"
)
)
Please see the result as follows.
Best Regards,
Angelia
- Anonymous8 years agoNot applicable
Thank you so much Angelia !