Rolling Average Numbers

Hey,
I'm strugguling with 2 things and I haven't been able to find anything related. So I'm trying to sum the past 12 months daily so I can then divided by 365 and save that number. Then I need to show side by side this new number rolling i.e day 1 of the month = 166, then day 2 of the month (166+166=332), then day 3 (332+166=498) and so on, while showing the current month numbers day 1 of the month 120, day 2 of the month (120+166=286), then day 3 of the month (286+200=486). I'm looking for a beast mode that can help me accomplish this. Appreciate any help!
Best Answers
-
Your question is a bit unclear.
For the last 12 months calculation, you can do something like this:sum(case when `your_date_field` >= dateadd(`your_date_field`, interval -1 year) and `your_date_field` <= `your_date_field` then `total_value` else 0 end)/365
Your second part is not clear. If there are 28 days of the month do you want to show all 28 days and their respective values? This would be very long and a tedious process as each day would have to be its case statement.
it could be something like:
CONCAT('DAY 1 ',DAY(`your_date_field`), ' ' ,sum(case when (MONTH(`your_date_field`) = MONTH(Current_date) and DAY(`your_date_field`) =1 then `total_value` else 0 end), ' DAY 2 ',DAY(`your_date_field`), sum(case when (MONTH(`your_date_field` ) = MONTH(Current_date) and DAY(`your_date_field`) >= 1 and DAY(`your_date_field)` <= 2 then `total_value` else 0 end),--and so on until 31).
I wasnt able to think of anything better. I am sure there could be a possibility of a more cleaner and faster code.0 -
Thank you for replying back, I know the ask was a bit complicated. We were able to pull it off, but required the use of the Lag function on the ETL and a tedious process of grouping the monthly numbers. Thank you for your input, appreciate it.
1
Answers
-
Your question is a bit unclear.
For the last 12 months calculation, you can do something like this:sum(case when `your_date_field` >= dateadd(`your_date_field`, interval -1 year) and `your_date_field` <= `your_date_field` then `total_value` else 0 end)/365
Your second part is not clear. If there are 28 days of the month do you want to show all 28 days and their respective values? This would be very long and a tedious process as each day would have to be its case statement.
it could be something like:
CONCAT('DAY 1 ',DAY(`your_date_field`), ' ' ,sum(case when (MONTH(`your_date_field`) = MONTH(Current_date) and DAY(`your_date_field`) =1 then `total_value` else 0 end), ' DAY 2 ',DAY(`your_date_field`), sum(case when (MONTH(`your_date_field` ) = MONTH(Current_date) and DAY(`your_date_field`) >= 1 and DAY(`your_date_field)` <= 2 then `total_value` else 0 end),--and so on until 31).
I wasnt able to think of anything better. I am sure there could be a possibility of a more cleaner and faster code.0 -
Thank you for replying back, I know the ask was a bit complicated. We were able to pull it off, but required the use of the Lag function on the ETL and a tedious process of grouping the monthly numbers. Thank you for your input, appreciate it.
1 -
No Problem!! If you can use SQL it is much easier taking that route. Glad you could figure it out.
1
Categories
- All Categories
- 2K Product Ideas
- 2K Ideas Exchange
- 1.6K Connect
- 1.3K Connectors
- 311 Workbench
- 6 Cloud Amplifier
- 9 Federated
- 3.8K Transform
- 657 Datasets
- 115 SQL DataFlows
- 2.2K Magic ETL
- 815 Beast Mode
- 3.3K Visualize
- 2.5K Charting
- 81 App Studio
- 45 Variables
- 775 Automate
- 190 Apps
- 481 APIs & Domo Developer
- 81 Workflows
- 23 Code Engine
- 40 AI and Machine Learning
- 20 AI Chat
- 1 AI Playground
- 1 AI Projects and Models
- 18 Jupyter Workspaces
- 410 Distribute
- 120 Domo Everywhere
- 280 Scheduled Reports
- 10 Software Integrations
- 144 Manage
- 140 Governance & Security
- 8 Domo Community Gallery
- 48 Product Releases
- 12 Domo University
- 5.4K Community Forums
- 41 Getting Started
- 31 Community Member Introductions
- 114 Community Announcements
- 4.8K Archive