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 )
1
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?
0 -
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 )
1
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