How to create a card with data from the calendar month before last
Hi, does anyone have any thoughts on how to create a card that contains rolling data for a calendar month that was 2 months ago?
Example 1, If today's date is June 15th, card should show data for the whole month of April
Example 2, If today's date is November 30th, card should show data for the whole month of September
Thanks all
Best Answer
-
You've got two options.
1) You could use a beast mode to determine if a date is from 2 months ago
CASE WHEN LAST_DAY(CURDATE() - INTERVAL '2' MONTH) = LAST_DAY(`Date Field`) THEN 1 ELSE 0 END
and then just filter on that value being 1.
This method you're always stuck looking at 2 months ago according to the current month. The next option is better in that it will allow you to look at 2 months ago based on any date you have selected in your chart.
2) The more robust option would be to create a custom date dimension table where you have customized offsets (With a report date and a comparison date). You'd then use a Fusion / View to join that dataset to your main dataset based on your date field and the comparison date field. You then can filter for your offset type of 2 months ago. This has been outlined several times here on the dojo. See https://dojo.domo.com/t5/Card-Building/show-percent-on-period-over-period-graph/m-p/50540/highlight/true#M7313.
I highly recommend method 2 as it gives you much more flexibility when processing and displaying your data.
Also @jaeW_at_Onyx has a nice video he put out which outlines this process as well:
**Was this post helpful? Click Agree or Like below**
**Did this solve your problem? Accept it as a solution!**2
Answers
-
You've got two options.
1) You could use a beast mode to determine if a date is from 2 months ago
CASE WHEN LAST_DAY(CURDATE() - INTERVAL '2' MONTH) = LAST_DAY(`Date Field`) THEN 1 ELSE 0 END
and then just filter on that value being 1.
This method you're always stuck looking at 2 months ago according to the current month. The next option is better in that it will allow you to look at 2 months ago based on any date you have selected in your chart.
2) The more robust option would be to create a custom date dimension table where you have customized offsets (With a report date and a comparison date). You'd then use a Fusion / View to join that dataset to your main dataset based on your date field and the comparison date field. You then can filter for your offset type of 2 months ago. This has been outlined several times here on the dojo. See https://dojo.domo.com/t5/Card-Building/show-percent-on-period-over-period-graph/m-p/50540/highlight/true#M7313.
I highly recommend method 2 as it gives you much more flexibility when processing and displaying your data.
Also @jaeW_at_Onyx has a nice video he put out which outlines this process as well:
**Was this post helpful? Click Agree or Like below**
**Did this solve your problem? Accept it as a solution!**2 -
Hi @GrantSmith - method 1 works perfectly and has now been rolled out to a suite of cards. For this purpose, being 'stuck' working from the current date is ok, the cards are being used to schedule a monthly export of raw data to a third party.
Method 2 is excellent for not relying on reference to the current date and I will no doubt use it in the future for another card.
Thanks for your help!
0 -
@richardjmarshall One piece of advise that I would offer. And this is just to provide some more clarity and flexibility to the field that you are filtering on. I would recommend not just using 'THEN 1 ELSE 0'
CASE WHEN LAST_DAY(CURDATE() - INTERVAL '2' MONTH) = LAST_DAY(`Date Field`) THEN '2 Months Ago' ELSE 'Other' END
Using something like this makes it more intuitive for anyone else using this filter to understand what they are filtering for. In addition, you could add more options:
CASE WHEN LAST_DAY(CURDATE() - INTERVAL '2' MONTH) = LAST_DAY(`Date Field`) THEN '2 Months Ago' WHEN LAST_DAY(CURDATE() - INTERVAL '1' MONTH) = LAST_DAY(`Date Field`) THEN '1 Month Ago' ... etc. ELSE 'Other' END
Users could then use this field to dynamically set a default view for any number of months they wanted the card to look back to.
“There is a superhero in all of us, we just need the courage to put on the cape.” -Superman0
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
- 732 Beast Mode
- 55 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
- 107 Community Announcements
- 4.8K Archive