Skip to main content
cancel
Showing results for 
Search instead for 
Did you mean: 

Register now to learn Fabric in free live sessions led by the best Microsoft experts. From Apr 16 to May 9, in English and Spanish.

Reply
Anni_E_Lehtinen
Frequent Visitor

Previous month function that takes January into consideration

Hi!

 

I have been trying to figure out a previous month- DAX function that takes into account that in January previous month's year is not the same as the current month's year. 

 

I am currently using this and this does work when it is not January:

 

IsPreviousMonth = IF(AND(MONTH(MarketingMonthly[Date]) =MONTH(TODAY()) -1,YEAR(MarketingMonthly[Date]) =YEAR(TODAY())),"Previous","Other")

 

However, in January it will be broken since previous month's year should be year -1 and not the current year.

 

Does anybody know how to do this? Thank you in advance!

1 ACCEPTED SOLUTION

Thanks @sdjensen! I actually just figured this out like this:

 

IsPreviousMonth = IF(MarketingMonthly[YearMonth]=FORMAT(DATE(YEAR(TODAY()),MONTH(TODAY())-1,DAY(TODAY())),"YYYY/MM"),"Previous","Other")

 

Problem solved 🙂 

View solution in original post

2 REPLIES 2
sdjensen
Solution Sage
Solution Sage

Add an IF to the calculation that check if the month is january - if true handle the calculation differently else do what do now.

/sdjensen

Thanks @sdjensen! I actually just figured this out like this:

 

IsPreviousMonth = IF(MarketingMonthly[YearMonth]=FORMAT(DATE(YEAR(TODAY()),MONTH(TODAY())-1,DAY(TODAY())),"YYYY/MM"),"Previous","Other")

 

Problem solved 🙂 

Helpful resources

Announcements
Microsoft Fabric Learn Together

Microsoft Fabric Learn Together

Covering the world! 9:00-10:30 AM Sydney, 4:00-5:30 PM CET (Paris/Berlin), 7:00-8:30 PM Mexico City

PBI_APRIL_CAROUSEL1

Power BI Monthly Update - April 2024

Check out the April 2024 Power BI update to learn about new features.

April Fabric Community Update

Fabric Community Update - April 2024

Find out what's new and trending in the Fabric Community.