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

Earn a 50% discount on the DP-600 certification exam by completing the Fabric 30 Days to Learn It challenge.

Reply
PhoenixBird66
Helper III
Helper III

DAX measure to return the Month Number from Previous 2 months

 

I need a DAX measure that will return the month number of 2 months prior to the current month (so today is January, and the Month Number is 01, but I want the Dax measure to return the month number for 2 months ago, which would be 11)

In order to do this previously I was using this measure:

 

2MonthsAgo = FORMAT([Today],"mm")-2

 

However, now that we're in January and the month number is 1, it's giving me the incorrect value of -1 instead of 11. When we're in February, I need the measure to return 12 (the Month number for December).

 

My [Today] meausure is Today = NOW() so the data type is uncategorised. 

 

Welcoming any suggestions for how I should get around this issue?

1 ACCEPTED SOLUTION
V-lianl-msft
Community Support
Community Support

Hi @PhoenixBird66 ,

 

Please try:

Measure = 
var now_month = MONTH(NOW())
return IF(now_month+10>12,now_month-2,now_month+10
)

V-lianl-msft_0-1610086530787.png

 

Best Regards,
Liang
If this post helps, then please consider Accept it as the solution to help the other members find it more quickly.

View solution in original post

4 REPLIES 4
V-lianl-msft
Community Support
Community Support

Hi @PhoenixBird66 ,

 

Please try:

Measure = 
var now_month = MONTH(NOW())
return IF(now_month+10>12,now_month-2,now_month+10
)

V-lianl-msft_0-1610086530787.png

 

Best Regards,
Liang
If this post helps, then please consider Accept it as the solution to help the other members find it more quickly.

amitchandak
Super User
Super User

@PhoenixBird66 , Use today function itself

 

2MonthsAgo = FORMAT(eomonth(date(today(),-2),"mm")

or

2MonthsAgo = month(eomonth(date(today(),-2))

Thanks for the suggestions. Sadly neither work for me. 

When I try the either suggestion i get the error "Too few arguments were passed to the DATE function. The minimum argument count for the function is 3."

@PhoenixBird66 , My bad try like

 

2MonthsAgo = FORMAT(eomonth(today(),-2),"mm")

or

2MonthsAgo = month(eomonth(today(),-2))

Helpful resources

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