Return Day with highest value - Case Statement
Hey guys I have a date column from Oct-Dec, a numeric column of totals from the date, and finally a categorical date column full of names.
I've attached a sample data table.
I'm using a beastmode that splits my dates into weeks.
I want to create a case statement that returns the value of the day from the week that had the highest total. This way, we can know which day from that week was the most active.
weekbymonth:
CONCAT(DATE_FORMAT(SUBDATE(`Date`,WEEKDAY(`Date`)-1),'%b %d'),' - ',DATE_FORMAT(SUBDATE(`Date`,WEEKDAY(`Date`)-7),'%b %d %Y'))
weekly_avg:
SUM((`video_plays`))
/
COUNT(DISTINCT DAYNAME(`date`))
avg_day:
(CASE ROUND(AVG(DAYOFWEEK(`date`)),0) WHEN 1 THEN 'Sunday'
WHEN 2 THEN 'Monday'
WHEN 3 THEN 'Tuesday'
WHEN 4 THEN 'Wednesday'
WHEN 5 THEN 'Thursday'
WHEN 6 THEN 'Friday'
WHEN 7 THEN 'Saturday'
END)
Comments
-
I think you can avoid a lot of this using some of the built-in card functionality in Domo.
First, have you tried using the Calendar card? It is great for this type of request as it turns a calendar into a heat map and would quickly show you the highest days of the week.
If you are doing a bar chart or similar, I would create a simple beast mode of: DAYNAME('date') that returns the name of the day of the week. I would put this in the x-axis and then put your video plays in the y-axis and set the aggregation to average. Then, use the date range filter in the top-right corner of the card to group by month or week, or whatever you need.
**Check out my Domo Tips & Tricks Videos
**Make sure to any users posts that helped you.
**Please mark as accepted the ones who solved your issue.0 -
If i'm understanding you correctly you want the week on the axis and then the day of the max total.
this is tough / not reallllllllly possible the way you want to without doing ETL (i don't think).
what you can do is SORT by RANK() -- such that the top ranked days of each week appear first, then the second best day of each week then the third etc.
to calculate RANK() you need window functions enabled (talk to your CSM) then set up the following beast mode:
sum(sum(1)) over (Partition By week_num order by sum(totals) desc)
You'll have to put week_num on the axis, as well as date and ideally the sum(totals) column
then sort by your RANK function ASC and date DESC
Then limit the number of rows displayed (in the data table at the bottom) to 10 or 15 to show the top date for the last n weeks.
cc @GrantSmith
Jae Wilson
Check out my 🎥 Domo Training YouTube Channel 👨💻
**Say "Thanks" by clicking the ❤️ in the post that helped you.
**Please mark the post that solves your problem by clicking on "Accept as Solution"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
- 626 Datasets
- 2.2K Magic ETL
- 3.9K Visualize
- 2.5K Charting
- 753 Beast Mode
- 61 App Studio
- 41 Variables
- 692 Automate
- 177 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