Previous Month
So I need to create a BM to give me the previous month, I use this as a filter for a report to send people the previous month's data. I found that with the year change my current formula does not catch December if it is January. I am looking for a filter to give me the rows where Entry Date is during the previous month.
case
when MONTH(CURDATE()) = MONTH(`Entry Date`) then 'This Month'
when MONTH(CURDATE()) - 1 = MONTH(`Entry Date`) then 'Last Month'
else 'Other Month'
end
I have a similar concept that looks for the next month and I found a way to use MOD in order to capture year changes. I tried applying the same concept in order to get the previous month but I could not get it. Here was my next month BM.
case
when MONTH(`Latest Hire date`) = MOD(MONTH(CURDATE()),12) + 1 then 'Next Month'
else 'Other'
end
For now I have added this line to my BM to give me the previous month when it is Jan but does anyone have something similar to the MOD fix that will allow me to just have one line to account for all cases? I hate having to do a manual case.
when MONTH(CURDATE()) = 1 and MONTH(`Entry Date`) = 12 then 'Last Month' -- manual fix to get December after year change
**If this answer solved your problem be sure to like it and accept it as a solution!
Comments
-
Just realized I don't even need a BM and could just use normal date operations for the card.
**If this answer solved your problem be sure to like it and accept it as a solution!
0 -
Hi @Ashleigh
There's several ways to tackle this. One possible way is to utilize a date dimension to calculate last month data. This has been outlined before on the Dojo.
Alternatively the quickest option would be to utilize the LAST_DAY function in your beast mode.
CASE WHEN LAST_DAY(`dt`) = LAST_DAY(CURRENT_DATE()) THEN 'This Month' WHEN LAST_DAY(`dt`) = LAST_DAY(DATE_SUB(CURRENT_DATE(), interval 1 month)) THEN 'Last Month' WHEN LAST_DAY(`dt`) = LAST_DAY(DATE_ADD(CURRENT_DATE(), interval 1 month)) THEN 'Next Month' ELSE 'Other Month' END
This will also protect against accidentally filtering data from a prior month and prior year (for example December 2019 and December 2020 for this month)
**Was this post helpful? Click Agree or Like below**
**Did this solve your problem? Accept it as a solution!**1 -
Alternatively yes, you can just filter for last month in the date selector which is probably the cleanest ?
**Was this post helpful? Click Agree or Like below**
**Did this solve your problem? Accept it as a solution!**1 -
@GrantSmith yea not sure why I never thought to use that before. I think with my other concept looking forward I had hire dates and was needing to know which anniversary dates were coming up so the default Domo options would not work. But for looking back I think they should work fine.
**If this answer solved your problem be sure to like it and accept it as a solution!
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
- 101 SQL DataFlows
- 622 Datasets
- 2.2K Magic ETL
- 3.9K Visualize
- 2.5K Charting
- 748 Beast Mode
- 60 App Studio
- 41 Variables
- 688 Automate
- 177 Apps
- 453 APIs & Domo Developer
- 48 Workflows
- 10 DomoAI
- 36 Predict
- 15 Jupyter Workspaces
- 21 R & Python Tiles
- 397 Distribute
- 114 Domo Everywhere
- 276 Scheduled Reports
- 7 Software Integrations
- 126 Manage
- 123 Governance & Security
- 8 Domo Community Gallery
- 38 Product Releases
- 10 Domo University
- 5.4K Community Forums
- 40 Getting Started
- 30 Community Member Introductions
- 109 Community Announcements
- 4.8K Archive