How to create date series with beast mode
I'm trying to create a series of data: Same Day, 0-14 Days, 15-30 Days, 31-60 Days, etc
I have 2 fields Created_Date and Closed_Date. If created_date = Closed_Date then "Same Day", if Closed_date - created_date < 14 days then 0-14 Days and so on.
My beast mode looks like this below. I was trying some stuff but anything over 30 days isn't working. I've tried date_sub, datediff, subdate, day but nothing seems to be working.
case when datediff(`Closed Date`, `Created Date`) = 0 then 'Same Day'
when DAY(`Closed Date`) - DAY(`Created Date`) < 14 then '0-14 Days'
when DAY(`Closed Date`) - DAY(`Created Date`) < 30 then '15-30 Days'
when DATEdiff(`Closed Date`, `Created Date`) < 60 then '31-60 Days'
when DATEdiff(`Closed Date`, `Created Date`) < 90 then '61-90 Days'
when DATEdiff(`Closed Date`, `Created Date`) < 120 then '91-120 Days'
when DATEdiff(`Closed Date`, `Created Date`) > 120 then '> 120 Days' end
Thoughts? Wendi
Comments
-
Nevermind I just corrected it by doing datediff to all columns
case when datediff(`Closed Date`, `Created Date`) = 0 then 'Same Day'
when DATEdiff(`Closed Date`, `Created Date`) < 14 then '0-14 Days'
when DATEdiff(`Closed Date`, `Created Date`) < 30 then '15-30 Days'
when DATEdiff(`Closed Date`, `Created Date`) < 60 then '31-60 Days'
when DATEdiff(`Closed Date`, `Created Date`) < 90 then '61-90 Days'
when DATEdiff(`Closed Date`, `Created Date`) < 120 then '91-120 Days'
when DATEdiff(`Closed Date`, `Created Date`) > 120 then '> 120 Days' end0 -
Just a quick note:
Your earlier iteration wasnt working (even for less than 30 days, but that would not have been obvious immediately) because of some quirks of SQL-based languages. Most of the date function take only one thing into account - in DAY() it is the day number of the month. This means if something is, say, created on the 31st of January and then closed on the 30th of March, that would show as '0-14 Days' (31-30=1).
Another thing you might want to keep in mind are year changes - datediff works for the number of days, but if you are interested in the number of months (and you want to avoid doing a complex beast mode to make sure something like 92 days becomes either 2 or 3 full months, depending on the date and number of months). We had to rework quite a bit of code when we realized that we couldnt use MONTH() AND YEAR() to account for year changes easily - PERIOD_DIFF() works well here (usually requires a DATE_FORMAT() though).
0 -
Ahh thank you!. Nice to know the information. Date_diff is working very well with my data when validating.
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