CASE statement if else Magic ETL
Hey guys I am trying to fill a column based on certain criteria from 4 columns.
I think it would be best to do this in another column so that I'm not overwriting anything.
My table looks like the following and I'm trying a Case Statement that fills in the null spaces, but I think my case statement is missing something or I'm missing a step.
publish_date | date_created | time_created | date_updated | time_updated |
04/30/2020 | 04/30/2020 | 18:37:06 | 04/30/2020 | 18:37:06 |
04/30/2020 | 04/30/2020 | 18:38:06 | 04/30/2020 | 18:38:06 |
04/30/2020 | 17:09:29 | 04/30/2020 | 17:09:29 | |
04/30/2020 | 04/30/2020 | 18:37:08 | 04/30/2020 | 18:43:11 |
04/30/2020 | 19:06:07 | 04/30/2020 | 19:06:07 | |
04/30/2020 | 04/30/2020 | 18:37:08 | 04/30/2020 | 18:43:11 |
04/30/2020 | 12:00:33 | 04/30/2020 | 12:00:36 | |
04/30/2020 | 04/30/2020 | 18:38:05 | 04/30/2020 | 22:31:32 |
My case statement looks like this so far:
CASE when `date_created`=`date_updated` and `time_created`=`time_updated` and `publish_date` IS NULL then `date_created` else `publish_date` end
Unfortunately my case statement sucks and this doesn't work to my advantage.
Can anyone help?
Comments
-
Hi @user052846
You didn't clearly state what exactly your issue was with your beast mode so I'm somewhat guessing here but you're essentially wanting to use the most recent date between publish date and update date for the publish date if the publish date is null correct?
If that's correct then you have two independent conditions dependent upon each other. Essentially you're saying the dates must be the same and publish date must be null in order for you to use the creation date. I'm assuming here too that your creation date and updated date will be the same when an entry is created. With those assumptions you can just narrow down your beast mode to using the updated date if the publish date is null.
Simplifies down to:
IFNULL(`publish_date`, `date_updated`)
**Was this post helpful? Click Agree or Like below**
**Did this solve your problem? Accept it as a solution!**0 -
a series of nested IFNULL statements will get the job done as per Grant's recommendation, but have a look at COALESCE() it will return the first non null value in a chain.
if you want to write it as a case statement then do a series of null checks
case
when colA is not null then colA
when colB is not null then colB
when colC is not null then colC
...
else ...
end
by definition you don't need to build extensive logic b/c in order for the second clause (test for to apply, colA must have been null (otherwise the preceeding logic step would have applied).
Jae Wilson
Check out my 🎥 Domo Training YouTube Channel 👨💻
**Say "Thanks" by clicking the ❤️ in the post that helped you.
**Please mark the post that solves your problem by clicking on "Accept as Solution"0
Categories
- All Categories
- 1.7K Product Ideas
- 1.7K Ideas Exchange
- 1.5K Connect
- 1.2K Connectors
- 292 Workbench
- 4 Cloud Amplifier
- 8 Federated
- 2.8K Transform
- 95 SQL DataFlows
- 603 Datasets
- 2.1K Magic ETL
- 3.7K Visualize
- 2.4K Charting
- 697 Beast Mode
- 43 App Studio
- 39 Variables
- 658 Automate
- 170 Apps
- 441 APIs & Domo Developer
- 42 Workflows
- 5 DomoAI
- 32 Predict
- 12 Jupyter Workspaces
- 20 R & Python Tiles
- 388 Distribute
- 111 Domo Everywhere
- 271 Scheduled Reports
- 6 Software Integrations
- 113 Manage
- 110 Governance & Security
- 9 Domo University
- 30 Product Releases
- Community Forums
- 40 Getting Started
- 30 Community Member Introductions
- 98 Community Announcements
- Domo Community Gallery
- 4.8K Archive