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.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