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
chat_peters
Helper III
Helper III

How to count back months from previous month if today is not the last day of the month

Hi!

I want to flag down dates that fall in the last 13 months. But there's an exception.

If today is not the last date of the month then I need to go to the previous month and count 13 months backwards. 

I understand I need an upper limit and a lower limit.

 

Upper limit = EOMONTH(NOW(),-1)

This is as far as I got. I need to count 13 months from the upper limit. Can someone please help me. 

1 ACCEPTED SOLUTION
AlexisOlson
Super User
Super User

I think you want something like this:

VAR _Today = TODAY ()
VAR _Today_Is_EoM = EOMONTH ( _Today, 0 ) = _Today
VAR _Upper = IF ( _Today_Is_EoM, EOMONTH ( _Today, -1 ), _Today )
VAR _Lower = EOMONTH ( _Upper, -13 )
VAR _Range_ =
    FILTER (
		DateTable,
		DateTable[Date] >= _Lower &&
		DateTable[Date] <= _Upper
	)
[...]

View solution in original post

2 REPLIES 2
AlexisOlson
Super User
Super User

I think you want something like this:

VAR _Today = TODAY ()
VAR _Today_Is_EoM = EOMONTH ( _Today, 0 ) = _Today
VAR _Upper = IF ( _Today_Is_EoM, EOMONTH ( _Today, -1 ), _Today )
VAR _Lower = EOMONTH ( _Upper, -13 )
VAR _Range_ =
    FILTER (
		DateTable,
		DateTable[Date] >= _Lower &&
		DateTable[Date] <= _Upper
	)
[...]

Thank you so much 😊

 

This worked perfect I tweaked the if statement part

VAR _Today = TODAY ()
VAR _Today_Is_EoM = EOMONTH ( _Today, 0 ) = _Today
VAR _Upper = IF ( _Today_Is_EoM, _Today, EOMONTH ( _Today, -1 ), _Today )
VAR _Lower = EOMONTH ( _Upper, -13 )
VAR _Range_ =
FILTER (
DateTable,
DateTable[Date] > _Lower &&
DateTable[Date] <= _Upper
)

It was counting Oct 31 of 2022 so I took the = off the evaluation part for lower piece

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.