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.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
- 58 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
- 395 Distribute
- 113 Domo Everywhere
- 276 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