Beast Mode: How to aggregate a value for 1yr and remainder of the yr from a date?
Hi - I am trying to figure out how to aggregate values from a run date thru the end of the year as well as aggregating from that same date as_of_date for 1 year out.
Essentially if the date is 5/31/23 it'll aggregate a value from that date through the end of the year (12/31/YY). Separately, from that same as of date (5/31/23) aggregate the value through the following year to 5/30/24. The as of dates are always changing so I'm trying to get the beast mode to pick the dates up correctly.
Best Answers
-
Gotcha! So then you would do something like this:
For the Date to the end of the year:
SUM(CASE WHEN `dateField` >= `as_of_date` AND `dateField` <= LAST_DAY(CURRENT_DATE() + INTERVAL (12 - MONTH(CURRENT_DATE())) MONTH) THEN `values` END)For the date to 1 year from that date:
SUM(CASE WHEN `dateField` >= `as_of_date` AND `dateField` < `as_of_date` + INTERVAL 1 YEAR THEN `values` END)If I solved your problem, please select "yes" above
0 -
This is perfect, it worked! Thank you
0
Answers
-
SUM(CASE WHEN `dateField` >= '2023-05-31' AND `dateField` <= '2023-12-31' THEN `values` END)
SUM(CASE WHEN `dateField` >= '2023-05-31' AND `dateField` <= '2024-05-30' THEN `values` END)
If the "as of date" is fixed and available somewhere that can be pulled into the dataset then the beastmodes would be a bit different, but without that you'd have to use the beastmodes above. If the "as of date" is always the current date (which it doesn't seem like it is) then you could use CURRENT_DATE() in your beastmode instead and then use INTERVAL logic to get the dates relative to the current date.
If I solved your problem, please select "yes" above
0 -
Hi - Thanks for the help. To give more clarity the as_of_date is a column in the dataset for ~100 rows per day with every day being an option(daily occurrence). The example of 5/31/23 was just one instance of this. I'm trying to get the beast mode to calc the remainder of the current calendar year and a rolling one year based on an as_of_date that can be any date. So the if it was from 7/31/23 it'd go to 7/30/24. Trying to avoid hardcoding in dates. Everything in the report is based off the 'as of date' and looking at the horizons
0 -
Gotcha! So then you would do something like this:
For the Date to the end of the year:
SUM(CASE WHEN `dateField` >= `as_of_date` AND `dateField` <= LAST_DAY(CURRENT_DATE() + INTERVAL (12 - MONTH(CURRENT_DATE())) MONTH) THEN `values` END)For the date to 1 year from that date:
SUM(CASE WHEN `dateField` >= `as_of_date` AND `dateField` < `as_of_date` + INTERVAL 1 YEAR THEN `values` END)If I solved your problem, please select "yes" above
0 -
This is perfect, it worked! Thank you
0 -
How would I add one more day to the 1 year equation? I tried these without success
'+ INTERVAL 1 YEAR + 1 Day'
'+ INTERVAL 1 YEAR and 1 Day'
'+ INTERVAL 1 YEAR 1 Day'
0 -
+ INTERVAL 1 YEAR + INTERVAL 1 DAY
or
+ INTERVAL 366 DAY
If I solved your problem, please select "yes" above
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.8K Visualize
- 2.5K Charting
- 738 Beast Mode
- 56 App Studio
- 40 Variables
- 684 Automate
- 176 Apps
- 452 APIs & Domo Developer
- 46 Workflows
- 10 DomoAI
- 35 Predict
- 14 Jupyter Workspaces
- 21 R & Python Tiles
- 394 Distribute
- 113 Domo Everywhere
- 275 Scheduled Reports
- 6 Software Integrations
- 123 Manage
- 120 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