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

Get Fabric Certified for FREE during Fabric Data Days. Don't miss your chance! Learn more

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
Fabric Data Days Carousel

Fabric Data Days

Advance your Data & AI career with 50 days of live learning, contests, hands-on challenges, study groups & certifications and more!

October Power BI Update Carousel

Power BI Monthly Update - October 2025

Check out the October 2025 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.