trends ratio for last 4 months
Hi,
I created this card last year and it was working fine but as the year has changed and I'm working with 4 months data so 2 are now in last year Nov & Dec and 2 Jan & Feb this year.
I tried working with Rank & Window function but running into problem with ASC and DESC
My second pic in Yellow is how I want the results.
Best Answer
-
I would change your beast mode to be like this:
CASE WHEN DATE_SUB(`dt`, INTERVAL (DAYOFMONTH(`dt`) - 1) DAY) = DATE_SUB(CURRENT_DATE(), INTERVAL (DAYOFMONTH(CURRENT_DATE()) - 1) DAY) THEN 'Current Month' WHEN DATE_SUB(`dt`, INTERVAL (DAYOFMONTH(`dt`) - 1) DAY) = DATE_SUB(DATE_SUB(CURRENT_DATE(), INTERVAL (DAYOFMONTH(CURRENT_DATE()) - 1) DAY), INTERVAL 1 MONTH) THEN 'Last Month' WHEN DATE_SUB(`dt`, INTERVAL (DAYOFMONTH(`dt`) - 1) DAY) = DATE_SUB(DATE_SUB(CURRENT_DATE(), INTERVAL (DAYOFMONTH(CURRENT_DATE()) - 1) DAY), INTERVAL 2 MONTH) THEN 'Month Prior' WHEN DATE_SUB(`dt`, INTERVAL (DAYOFMONTH(`dt`) - 1) DAY) = DATE_SUB(DATE_SUB(CURRENT_DATE(), INTERVAL (DAYOFMONTH(CURRENT_DATE()) - 1) DAY), INTERVAL 3 MONTH) THEN '2 Months Prior' END
To break this down, I am using the date_sub and dayofmonth to be able to evaluate the dates as the first day of each month. In the 2nd, 3rd and 4th when statements, I am wrapping another date_sub around the current date to subtract additional months. This will allow you to handle the changing of years without breaking anything.
**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.2
Answers
-
I would try and sort on a single date field. If you don't already have it, and you just have the individual month and year columns, you can construct a date field like this in a formula tile.
DATE(CONCAT(`Month`,'/1/',`Year`))
Add this formula tile just before your rank and window tile and then sort on this date field descending. You can then add a row number or rank and then later filter to where it is 4 or less to get the most recent 4, if you need to limit it in your dataset.
**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.1 -
I do have a Date field, as not every products sells every day so the row # will be different.
I'm don't think I understand the though process here with Rank.
0 -
If you do have a date field, you can normalize a couple different ways to get them to be grouped by month and year. The easiest is probably using the Last_Day() function, like this (replacing dt with your fieldname that has the date:
LAST_DAY(`dt`)
This will create a date field for you and have all the transactions in a given month have the same date. You can then use this field in your rank and window and order by this field descending. Try that for starters before tackling the rank and see how it looks for you.
**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.3 -
Sorry, I'm working on too many things altogether and the thought process is scrambled.
It's the Ratio Trend up that I'm trying to show on card,
the Beast mode for that is
CASE WHEN `Ratio % Last Month` > `Ratio % Month Prior` AND `Ratio % Month Prior` > `Ratio % 2 Month Prior`
THEN 1
END
and this should be the result.
I was getting the Months by using the Beast mode, because of the year difference this is not working any more.
CASE
WHEN `Month` = `Current Month` THEN 'Current Month'
WHEN `Month` = `Current Month` - 1 THEN 'Last Month'
WHEN `Month` = `Current Month` - 2 THEN 'Month Prior'
WHEN `Month` = `Current Month` - 3 THEN '2 Month Prior'
END
0 -
I would change your beast mode to be like this:
CASE WHEN DATE_SUB(`dt`, INTERVAL (DAYOFMONTH(`dt`) - 1) DAY) = DATE_SUB(CURRENT_DATE(), INTERVAL (DAYOFMONTH(CURRENT_DATE()) - 1) DAY) THEN 'Current Month' WHEN DATE_SUB(`dt`, INTERVAL (DAYOFMONTH(`dt`) - 1) DAY) = DATE_SUB(DATE_SUB(CURRENT_DATE(), INTERVAL (DAYOFMONTH(CURRENT_DATE()) - 1) DAY), INTERVAL 1 MONTH) THEN 'Last Month' WHEN DATE_SUB(`dt`, INTERVAL (DAYOFMONTH(`dt`) - 1) DAY) = DATE_SUB(DATE_SUB(CURRENT_DATE(), INTERVAL (DAYOFMONTH(CURRENT_DATE()) - 1) DAY), INTERVAL 2 MONTH) THEN 'Month Prior' WHEN DATE_SUB(`dt`, INTERVAL (DAYOFMONTH(`dt`) - 1) DAY) = DATE_SUB(DATE_SUB(CURRENT_DATE(), INTERVAL (DAYOFMONTH(CURRENT_DATE()) - 1) DAY), INTERVAL 3 MONTH) THEN '2 Months Prior' END
To break this down, I am using the date_sub and dayofmonth to be able to evaluate the dates as the first day of each month. In the 2nd, 3rd and 4th when statements, I am wrapping another date_sub around the current date to subtract additional months. This will allow you to handle the changing of years without breaking anything.
**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.2 -
Thank you!
0
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