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
- 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
- 627 Datasets
- 2.2K Magic ETL
- 3.9K Visualize
- 2.5K Charting
- 755 Beast Mode
- 61 App Studio
- 41 Variables
- 693 Automate
- 178 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