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.9K Product Ideas
- 1.9K Ideas Exchange
- 1.6K Connect
- 1.3K Connectors
- 302 Workbench
- 6 Cloud Amplifier
- 9 Federated
- 2.9K Transform
- 104 SQL DataFlows
- 637 Datasets
- 2.2K Magic ETL
- 3.9K Visualize
- 2.5K Charting
- 761 Beast Mode
- 65 App Studio
- 42 Variables
- 703 Automate
- 182 Apps
- 458 APIs & Domo Developer
- 53 Workflows
- 10 DomoAI
- 39 Predict
- 16 Jupyter Workspaces
- 23 R & Python Tiles
- 401 Distribute
- 116 Domo Everywhere
- 277 Scheduled Reports
- 8 Software Integrations
- 132 Manage
- 129 Governance & Security
- 8 Domo Community Gallery
- 38 Product Releases
- 12 Domo University
- 5.4K Community Forums
- 40 Getting Started
- 30 Community Member Introductions
- 111 Community Announcements
- 4.8K Archive