Last 4 weeks accumulated beast mode
Hello,
I'm trying to write a beast modes that shows the last 4 weeks as Last Week, the previous 4 weeks before that as Previous Week, and the last 4 weeks prior year as Prior Year.
The reason why I will create 3 beast modes is because only want 3 columns showing for these accumulated week periods, versus showing 52 columns total (weekly column)
The follow is a beast mode for last week:
SUM(CASE WHEN (
DATE((CASE WHEN DAYOFWEEK(`SentDate`) = 1 THEN `SentDate`
WHEN DAYOFWEEK(`SentDate`) > 1 THEN ADDDATE(`SentDate`, 8-DAYOFWEEK(`SentDate`))
END)) =
DATE(DATE_SUB((CASE WHEN DAYOFWEEK(CURDATE()) = 1 THEN CURDATE()
WHEN DAYOFWEEK(CURDATE()) > 1 THEN ADDDATE(CURDATE(), 8-DAYOFWEEK(CURDATE()))
END), INTERVAL 1 WEEK))
)
THEN `NumberDelivered` END)
Can anyone advise?
Thank you,
Summer
Best Answer
-
Thank you for responding!
I've found a solution,
For last 4 weeks:
CASE WHEN YEARWEEK(`SentDate`,1) >= YEARWEEK(CURDATE(),1)-4 AND YEARWEEK(`SentDate`,1) < YEARWEEK(CURDATE(),1) THEN `METRICNAME` END
For last 8 weeks:
((CASE WHEN YEARWEEK(`SentDate`,1) >= YEARWEEK(CURDATE(),1)-8 AND YEARWEEK(`SentDate`,1) < YEARWEEK(CURDATE(),1) THEN `METRICNAME` END)
-
(CASE WHEN YEARWEEK(`SentDate`,1) >= YEARWEEK(CURDATE(),1)-4 AND YEARWEEK(`SentDate`,1) < YEARWEEK(CURDATE(),1) THEN `METRICNAME` END))
0
Answers
-
Hi Summer,
Can you just do something like ...
CASE WHEN SentDate >= current_date - interval 28 day then 'Last Week'
WHEN SentDate >= current_date - interval 56 day and SentDate < current_date - interval 28 day then 'Previous Week'
WHEN SentDate >= DATE_SUB((DATE_SUB(current_date, INTERVAL 1 year)), INTERVAL 28 DAY) and SentDate <= current_date - interval 1 year as 'Prior Year' ENDThen this would be your x axis and NumberDelivered could be your Y Axis
Hope this helps,
Brian
**Please mark "Accept as Solution" if this post solves your problem
**Say "Thanks" by clicking the "heart" in the post that helped you.1 -
Thank you for responding!
I've found a solution,
For last 4 weeks:
CASE WHEN YEARWEEK(`SentDate`,1) >= YEARWEEK(CURDATE(),1)-4 AND YEARWEEK(`SentDate`,1) < YEARWEEK(CURDATE(),1) THEN `METRICNAME` END
For last 8 weeks:
((CASE WHEN YEARWEEK(`SentDate`,1) >= YEARWEEK(CURDATE(),1)-8 AND YEARWEEK(`SentDate`,1) < YEARWEEK(CURDATE(),1) THEN `METRICNAME` END)
-
(CASE WHEN YEARWEEK(`SentDate`,1) >= YEARWEEK(CURDATE(),1)-4 AND YEARWEEK(`SentDate`,1) < YEARWEEK(CURDATE(),1) THEN `METRICNAME` END))
0
Categories
- All Categories
- 1.7K Product Ideas
- 1.7K Ideas Exchange
- 1.5K Connect
- 1.2K Connectors
- 292 Workbench
- 4 Cloud Amplifier
- 8 Federated
- 2.8K Transform
- 95 SQL DataFlows
- 605 Datasets
- 2.1K Magic ETL
- 3.7K Visualize
- 2.4K Charting
- 696 Beast Mode
- 43 App Studio
- 39 Variables
- 660 Automate
- 170 Apps
- 442 APIs & Domo Developer
- 42 Workflows
- 6 DomoAI
- 33 Predict
- 13 Jupyter Workspaces
- 20 R & Python Tiles
- 388 Distribute
- 111 Domo Everywhere
- 271 Scheduled Reports
- 6 Software Integrations
- 113 Manage
- 110 Governance & Security
- 9 Domo University
- 31 Product Releases
- Community Forums
- 40 Getting Started
- 30 Community Member Introductions
- 98 Community Announcements
- Domo Community Gallery
- 4.8K Archive