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.8K Product Ideas
- 1.8K Ideas Exchange
- 1.6K Connect
- 1.2K Connectors
- 300 Workbench
- 6 Cloud Amplifier
- 9 Federated
- 2.9K Transform
- 102 SQL DataFlows
- 626 Datasets
- 2.2K Magic ETL
- 3.9K Visualize
- 2.5K Charting
- 753 Beast Mode
- 61 App Studio
- 41 Variables
- 692 Automate
- 177 Apps
- 456 APIs & Domo Developer
- 49 Workflows
- 10 DomoAI
- 38 Predict
- 16 Jupyter Workspaces
- 22 R & Python Tiles
- 398 Distribute
- 115 Domo Everywhere
- 276 Scheduled Reports
- 7 Software Integrations
- 130 Manage
- 127 Governance & Security
- 8 Domo Community Gallery
- 38 Product Releases
- 11 Domo University
- 5.4K Community Forums
- 40 Getting Started
- 30 Community Member Introductions
- 110 Community Announcements
- 4.8K Archive