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

Enhance your career with this limited time 50% discount on Fabric and Power BI exams. Ends September 15. Request your voucher.

Reply
Anonymous
Not applicable

DAX

The formula below works for calculating the cumulative total by year, displaying null values when past current date. Is there a way I can make the formula stop calculating the cumulative total at the previous month rather than the current month. 

 

I would expect changing the line below to -1 to work but this only removes January from my pivot table: 

 

var __prevMonthEndDate = EOMONTH(__currentMaxDate, -1)

 

Cumulative E&A Wells (Previous Month):=var __currentMaxDate = MAX('Calendar'[Date])
var __currentMinDate = MIN('Calendar'[Date])
var __today = TODAY()
var __prevMonthEndDate = EOMONTH(__currentMaxDate, 0)
var __cumulativevalue =
CALCULATE(
COUNTROWS('FM Full Export'),
DATESYTD('Calendar'[Date]),
'Calendar'[Date] <= __prevMonthEndDate,
ALLSELECTED('Calendar'[Date])
)
var __shouldDisplay =
--check if the current period is fully contained in the future
NOT(__currentMinDate >= __today)
return
IF(__shouldDisplay, __cumulativevalue)

 

Many thanks

1 REPLY 1
Stachu
Community Champion
Community Champion

what is selected in the slicer on the calendar table? or how is it desplayed in the visual?
from what I see the measure should return the same results  even if you skip the 

'Calendar'[Date] <= __prevMonthEndDate,

because it will always be more constrained by the

DATESYTD('Calendar'[Date]),

so I am quite puzzled how it gives you the 'previous month' - previous in reference to what exactly?



Did I answer your question? Mark my post as a solution!
Thank you for the kudos 🙂

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.