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.8K Product Ideas
- 1.8K Ideas Exchange
- 1.5K Connect
- 1.2K Connectors
- 300 Workbench
- 6 Cloud Amplifier
- 8 Federated
- 2.9K Transform
- 100 SQL DataFlows
- 616 Datasets
- 2.2K Magic ETL
- 3.9K Visualize
- 2.5K Charting
- 738 Beast Mode
- 57 App Studio
- 40 Variables
- 685 Automate
- 176 Apps
- 452 APIs & Domo Developer
- 47 Workflows
- 10 DomoAI
- 36 Predict
- 15 Jupyter Workspaces
- 21 R & Python Tiles
- 394 Distribute
- 113 Domo Everywhere
- 275 Scheduled Reports
- 6 Software Integrations
- 124 Manage
- 121 Governance & Security
- 8 Domo Community Gallery
- 38 Product Releases
- 10 Domo University
- 5.4K Community Forums
- 40 Getting Started
- 30 Community Member Introductions
- 108 Community Announcements
- 4.8K Archive