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

Compete to become Power BI Data Viz World Champion! First round ends August 18th. Get started.

Reply
rogerthat
Helper I
Helper I

Dax Measure to handle last month for DEC and Today() JAN

Hello,

 

 

I'm trying to count all records that have been created YTD, up till last month.

 

Meaning Jan-Oct.

Previous Month = MONTH(TODAY())-1

However, I'm trying to get the logic of when today is actually Janurary, would it be smart enough to get 12?

Or should I write an "if" to handle this stituation? And if so, how would I accomplish this. Kinda stuck here.

 

TIA~

 
1 ACCEPTED SOLUTION
AlexisOlson
Super User
Super User

No, it won't give you 12 when TODAY() is in January.

 

You can handle that case specifically,

 

Previous Month =
VAR CurrMonth = MONTH ( TODAY () )
RETURN
    IF ( CurrMonth = 1, 12, CurrMonth - 1 )

 

 

Or take a slightly different approach:

 

Previous Month = MONTH ( EOMONTH ( TODAY (), -1 ) )

 

 

Or use MOD:

 

Previous Month = MOD ( MONTH ( TODAY () ) - 2, 12 ) + 1

 

View solution in original post

2 REPLIES 2
AlexisOlson
Super User
Super User

No, it won't give you 12 when TODAY() is in January.

 

You can handle that case specifically,

 

Previous Month =
VAR CurrMonth = MONTH ( TODAY () )
RETURN
    IF ( CurrMonth = 1, 12, CurrMonth - 1 )

 

 

Or take a slightly different approach:

 

Previous Month = MONTH ( EOMONTH ( TODAY (), -1 ) )

 

 

Or use MOD:

 

Previous Month = MOD ( MONTH ( TODAY () ) - 2, 12 ) + 1

 

I was able to get it right before your response, I circled back and forth haha but did something simialr to what you suggested!

 

Thanks!! 😅

Helpful resources

Announcements
August Power BI Update Carousel

Power BI Monthly Update - August 2025

Check out the August 2025 Power BI update to learn about new features.

August 2025 community update carousel

Fabric Community Update - August 2025

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