Using Date value within Case statement.
In the below case statement I am trying to look at product that is on order to our warehouse, and have it breakout by expected arrival timeframes. I am not sure if casting the `RDC_ETA_STATUS` as a date or using a value of current date() + is a potential way of creating the ranges so any help would be appreciated.
(CASE
WHEN (`OW_TO_STORE` = 'X') THEN '01. Store OW'
WHEN (`DC_OH` > 0) THEN '02. RDC OH'
WHEN (`RDC_OO` > 0) and DATE(`RDC_ETA_STATUS`)=CURRENT_DATE() THEN '06a. RDC OO Due Today'
WHEN (`RDC_OO` > 0) and DATE(`RDC_ETA_STATUS`)=CURRENT_DATE()+1 THEN '06b. RDC OO Due Tomorrow'
WHEN (`RDC_OO` > 0) and DATE(`RDC_ETA_STATUS`)=CURRENT_DATE()+2 THEN '06c. RDC OO Due In 2 Days'
WHEN (`RDC_OO` > 0) and DATE(`RDC_ETA_STATUS`)>CURRENT_DATE()+2 and DATE(`RDC_ETA_STATUS`)<CURRENT_DATE()+5 THEN '06d. RDC OO Due in 3-4 days'
WHEN (`RDC_OO` > 0) and DATE(`RDC_ETA_STATUS`)>CURRENT_DATE()+4 and DATE(`RDC_ETA_STATUS`)<CURRENT_DATE()+8 THEN '06e. RDC OO Due in 5- 7 days'
WHEN (`RDC_OO` > 0) and DATE(`RDC_ETA_STATUS`)>CURRENT_DATE()+7 and DATE(`RDC_ETA_STATUS`)<CURRENT_DATE()+15 THEN '06f. RDC OO Due in 8-14 days'
WHEN (`RDC_OO` > 0) and DATE(`RDC_ETA_STATUS`)>CURRENT_DATE()+14 THEN '06g. RDC OO Due in >14 days'
WHEN (`NOTHING_AT_LOC` = 'X') THEN '10. Nothing'
ELSE 'Unclassified'
END )
Best Answer
-
For your Date ranges, I would suggest usind DATEDIFF()
(CASE
WHEN (`OW_TO_STORE` = 'X') THEN '01. Store OW'
WHEN (`DC_OH` > 0) THEN '02. RDC OH'
WHEN (`RDC_OO` > 0) and DATEDIFF(`RDC_ETA_STATUS`,CURRENT_DATE())=0 THEN '06a. RDC OO Due Today'
WHEN (`RDC_OO` > 0) and DATEDIFF(`RDC_ETA_STATUS`,CURRENT_DATE())=1 THEN '06b. RDC OO Due Tomorrow'
WHEN (`RDC_OO` > 0) and DATEDIFF(`RDC_ETA_STATUS`,CURRENT_DATE())=2 THEN '06c. RDC OO Due In 2 Days'
WHEN (`RDC_OO` > 0) and DATEDIFF(`RDC_ETA_STATUS`,CURRENT_DATE())<5 THEN '06d. RDC OO Due in 3-4 days'
WHEN (`RDC_OO` > 0) and DATEDIFF(`RDC_ETA_STATUS`,CURRENT_DATE())<8 THEN '06e. RDC OO Due in 5- 7 days'
WHEN (`RDC_OO` > 0) and DATEDIFF(`RDC_ETA_STATUS`,CURRENT_DATE())<15 THEN '06f. RDC OO Due in 8-14 days'
WHEN (`RDC_OO` > 0) and DATEDIFF(`RDC_ETA_STATUS`,CURRENT_DATE())>14 THEN '06g. RDC OO Due in >14 days'WHEN (`NOTHING_AT_LOC` = 'X') THEN '10. Nothing'
ELSE 'Unclassified'END )
“There is a superhero in all of us, we just need the courage to put on the cape.” -Superman1
Answers
-
What is the Data type for `RDC_ETA_STATUS`?
Would you mind providing some sample data so we can understand your data set a little better?
Is the current beastmode giving you an error message? Or just the wrong result?
“There is a superhero in all of us, we just need the courage to put on the cape.” -Superman0 -
For your Date ranges, I would suggest usind DATEDIFF()
(CASE
WHEN (`OW_TO_STORE` = 'X') THEN '01. Store OW'
WHEN (`DC_OH` > 0) THEN '02. RDC OH'
WHEN (`RDC_OO` > 0) and DATEDIFF(`RDC_ETA_STATUS`,CURRENT_DATE())=0 THEN '06a. RDC OO Due Today'
WHEN (`RDC_OO` > 0) and DATEDIFF(`RDC_ETA_STATUS`,CURRENT_DATE())=1 THEN '06b. RDC OO Due Tomorrow'
WHEN (`RDC_OO` > 0) and DATEDIFF(`RDC_ETA_STATUS`,CURRENT_DATE())=2 THEN '06c. RDC OO Due In 2 Days'
WHEN (`RDC_OO` > 0) and DATEDIFF(`RDC_ETA_STATUS`,CURRENT_DATE())<5 THEN '06d. RDC OO Due in 3-4 days'
WHEN (`RDC_OO` > 0) and DATEDIFF(`RDC_ETA_STATUS`,CURRENT_DATE())<8 THEN '06e. RDC OO Due in 5- 7 days'
WHEN (`RDC_OO` > 0) and DATEDIFF(`RDC_ETA_STATUS`,CURRENT_DATE())<15 THEN '06f. RDC OO Due in 8-14 days'
WHEN (`RDC_OO` > 0) and DATEDIFF(`RDC_ETA_STATUS`,CURRENT_DATE())>14 THEN '06g. RDC OO Due in >14 days'WHEN (`NOTHING_AT_LOC` = 'X') THEN '10. Nothing'
ELSE 'Unclassified'END )
“There is a superhero in all of us, we just need the courage to put on the cape.” -Superman1
Categories
- All Categories
- 1.7K Product Ideas
- 1.7K Ideas Exchange
- 1.5K Connect
- 1.2K Connectors
- 294 Workbench
- 6 Cloud Amplifier
- 8 Federated
- 2.8K Transform
- 97 SQL DataFlows
- 607 Datasets
- 2.1K Magic ETL
- 3.8K Visualize
- 2.4K Charting
- 707 Beast Mode
- 49 App Studio
- 39 Variables
- 667 Automate
- 170 Apps
- 446 APIs & Domo Developer
- 44 Workflows
- 7 DomoAI
- 33 Predict
- 13 Jupyter Workspaces
- 20 R & Python Tiles
- 391 Distribute
- 111 Domo Everywhere
- 274 Scheduled Reports
- 6 Software Integrations
- 115 Manage
- 112 Governance & Security
- Domo Community Gallery
- 31 Product Releases
- 9 Domo University
- 5.3K Community Forums
- 40 Getting Started
- 30 Community Member Introductions
- 103 Community Announcements
- 4.8K Archive