Previous Month

Reply
Major Brown Belt

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

Major Brown Belt

Just realized I don't even need a BM and could just use normal date operations for the card. 

Black Belt

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 the heart icon**

**Did this solve your problem? Accept it as a solution!**
Black Belt

Alternatively yes, you can just filter for last month in the date selector which is probably the cleanest 🙂



**Was this post helpful? Click the heart icon**

**Did this solve your problem? Accept it as a solution!**
Major Brown Belt

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

Announcements
New & Improved Dojo: Get excited for a new feel and additional features in the online community.

Site will be down February 4-5th for maintenance.

Launch coming February 8th!