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

Vote for your favorite vizzies from the Power BI Dataviz World Championship submissions. Vote now!

Reply
Anonymous
Not applicable

Issue with EOMONTH Function

Hello, I am using the following DAX expression, which works as intended with the correct filtering:

 
Count =
VAR _start = EOMONTH(TODAY(),-4)
VAR _result = CALCULATE(COUNTROWS(Gains),Gains[Effective Date]>=_start)
RETURN _result
 
However, instead of using the TODAY() function to pass the current date to EOMONTH, I would prefer instead to pass the latest date in the table.  I thought this would be easy by replacing TODAY() with MAX(Gains[Effective Date]:
 
Count =
VAR _start = EOMONTH(MAX(Gains[Effective Date]),-4)
VAR _result = CALCULATE(COUNTROWS(Gains),Gains[Effective Date]>=_start)
RETURN _result
 
However, this doesn't work and the results are returned as if no filtering takes place.  I've tried everything I can to troubleshoot, and have ensured that the date column is formatted as a date.
 
Thanks for your help!
1 ACCEPTED SOLUTION
amustafa
Solution Sage
Solution Sage

When you use `TODAY()`, it's straightforward because it always returns the current date, regardless of any filter context. However, when you use `MAX(Gains[Effective Date])`, the result depends on the current filter context.

To ensure that `MAX` calculates the maximum date over the entire `Gains` table, regardless of any filters that might be applied elsewhere in your report or calculations, you can use the `ALL` function to remove any filters from the `Gains[Effective Date]` column. Here's how you can modify your measure:

 

 

Count =
VAR _latestDate = CALCULATE(MAX(Gains[Effective Date]), ALL(Gains))
VAR _start = EOMONTH(_latestDate, -4)
VAR _result = CALCULATE(COUNTROWS(Gains), Gains[Effective Date] >= _start)
RETURN _result

 

 





Did I answer your question? Mark my post as a solution!

Proud to be a Super User!




View solution in original post

2 REPLIES 2
amustafa
Solution Sage
Solution Sage

When you use `TODAY()`, it's straightforward because it always returns the current date, regardless of any filter context. However, when you use `MAX(Gains[Effective Date])`, the result depends on the current filter context.

To ensure that `MAX` calculates the maximum date over the entire `Gains` table, regardless of any filters that might be applied elsewhere in your report or calculations, you can use the `ALL` function to remove any filters from the `Gains[Effective Date]` column. Here's how you can modify your measure:

 

 

Count =
VAR _latestDate = CALCULATE(MAX(Gains[Effective Date]), ALL(Gains))
VAR _start = EOMONTH(_latestDate, -4)
VAR _result = CALCULATE(COUNTROWS(Gains), Gains[Effective Date] >= _start)
RETURN _result

 

 





Did I answer your question? Mark my post as a solution!

Proud to be a Super User!




Anonymous
Not applicable

Brilliant!  This did the trick - thank you so much!

Helpful resources

Announcements
Sticker Challenge 2026 Carousel

Join our Community Sticker Challenge 2026

If you love stickers, then you will definitely want to check out our Community Sticker Challenge!

January Power BI Update Carousel

Power BI Monthly Update - January 2026

Check out the January 2026 Power BI update to learn about new features.

FabCon Atlanta 2026 carousel

FabCon Atlanta 2026

Join us at FabCon Atlanta, March 16-20, for the ultimate Fabric, Power BI, AI and SQL community-led event. Save $200 with code FABCOMM.