What's wrong with this case when statement / how do case when's operate on the back end?

Hello! I'm having a problem with a case when statement, and it seems like its not working because I don't fully understand how/when Case When's output information, especially when nested. Here's the code for my new variable `CurrentWeekofYear`
case when `Week Number` = (case when `WorkDate`=TODAY() then `Week Number` end) then 'Current Week' /*equals --current week number*/ else 'Not Current Week' end
I have a variable, `Week Number` , where I have the week of the year that the variable WorkDate
falls under. I want my beast mode to check each record, and see if the week number of that record is the same week number of the current day, and then output 'Current Week' if the statement is true, and 'Not Current Week' if the statement is not true.
However, with the code I have, I only get results if 'Current Week' when the WorkDate
is the same as today's current date. The other days of the same week still say 'Not Current Week' (I inserted a fake example below, with the mislabeled row highlighted) Can someone help me understand why this is happening? And maybe point me to a resource where I can can better understand how/when case when statements operate?
Best Answer
-
The issue is because your function is only going to return the week number variable when work date equals today. You can do this much simpler by using this as your beast mode:
case when `Week Number` = WEEKOFYEAR(CURRENT_DATE()) then 'Current Week' else 'Not Current Week' end
You could also choose to use your workdate field instead of your weeknumber field by changing your beast mode to this:
case when WEEKOFYEAR(`WorkDate`) = WEEKOFYEAR(CURRENT_DATE()) then 'Current Week' else 'Not Current Week' end
You can use whichever is easier for you to read.
**Check out my Domo Tips & Tricks Videos
**Make sure toany users posts that helped you.
**Please mark as accepted the ones who solved your issue.2
Answers
-
The issue is because your function is only going to return the week number variable when work date equals today. You can do this much simpler by using this as your beast mode:
case when `Week Number` = WEEKOFYEAR(CURRENT_DATE()) then 'Current Week' else 'Not Current Week' end
You could also choose to use your workdate field instead of your weeknumber field by changing your beast mode to this:
case when WEEKOFYEAR(`WorkDate`) = WEEKOFYEAR(CURRENT_DATE()) then 'Current Week' else 'Not Current Week' end
You can use whichever is easier for you to read.
**Check out my Domo Tips & Tricks Videos
**Make sure toany users posts that helped you.
**Please mark as accepted the ones who solved your issue.2 -
Thanks!
1 -
No problem. If you can mark my answer as accepted, that will help others in the community.
**Check out my Domo Tips & Tricks Videos
**Make sure toany users posts that helped you.
**Please mark as accepted the ones who solved your issue.0
Categories
- All Categories
- 1.9K Product Ideas
- 1.9K Ideas Exchange
- 1.6K Connect
- 1.3K Connectors
- 306 Workbench
- 6 Cloud Amplifier
- 9 Federated
- 3K Transform
- 112 SQL DataFlows
- 649 Datasets
- 2.2K Magic ETL
- 4K Visualize
- 2.5K Charting
- 787 Beast Mode
- 78 App Studio
- 43 Variables
- 742 Automate
- 187 Apps
- 474 APIs & Domo Developer
- 67 Workflows
- 14 DomoAI
- 40 Predict
- 17 Jupyter Workspaces
- 23 R & Python Tiles
- 406 Distribute
- 117 Domo Everywhere
- 279 Scheduled Reports
- 10 Software Integrations
- 139 Manage
- 136 Governance & Security
- 8 Domo Community Gallery
- 44 Product Releases
- 12 Domo University
- 5.4K Community Forums
- 40 Getting Started
- 30 Community Member Introductions
- 113 Community Announcements
- 4.8K Archive