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.4K Product Ideas
- 1.4K Ideas Exchange
- 1.4K Connect
- 1.1K Connectors
- 282 Workbench
- 3 Cloud Amplifier
- 4 Federated
- 2.8K Transform
- 86 SQL DataFlows
- 548 Datasets
- 2.2K Magic ETL
- 3.2K Visualize
- 2.3K Charting
- 544 Beast Mode
- App Studio
- 26 Variables
- 566 Automate
- 134 Apps
- 411 APIs & Domo Developer
- 21 Workflows
- DomoAI
- 28 Predict
- 12 Jupyter Workspaces
- 16 R & Python Tiles
- 345 Distribute
- 87 Domo Everywhere
- 257 Scheduled Reports
- 1 Software Integrations
- 85 Manage
- 84 Governance & Security
- 8 Product Release Questions
- Community Forums
- 41 Getting Started
- 27 Community Member Introductions
- 81 Community Announcements
- 4.8K Archive