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

Join the Fabric FabCon Global Hackathon—running virtually through Nov 3. Open to all skill levels. $10,000 in prizes! Register now.

Reply
Anonymous
Not applicable

Dax - Previous Month

I need some help changing the formula below. At present the formula calculates a cumulative total up to the current date.

 

Cumulative E&A Wells (Today):=

var __currentMaxDate = MAX('Calendar'[Date])
var __currentMinDate = MIN('Calendar'[Date])
var __today = TODAY()
var __cumulativevalue =
CALCULATE(
COUNTROWS('FM Full Export'),
DATESYTD('Calendar'[Date]),
'Calendar'[Date] <= __currentMaxDate,
ALLSELECTED('Calendar'[Date])
)
var __shouldDisplay =
--check if the current period is fully contained in the future
NOT(__currentMinDate >= __today)
return
IF(__shouldDisplay, __cumulativevalue)

 

I need the formula to calculate a cumulative total only up to the previous month but when I change the formula to the below and try to make a pivot table I get an error telling me the "A table of multiple values was supplied where a single value was expected". I understand why this error is appearing but cannot figure out how to request the previous month cumulative total.

 

Cumulative E&A Wells (Previous Month):=

var __currentMaxDate = MAX('Calendar'[Date])
var __currentMinDate = MIN('Calendar'[Date])
var __previousmonth = PREVIOUSMONTH('Calendar'[Date])
var __cumulativevalue =
CALCULATE(
COUNTROWS('FM Full Export'),
DATESYTD('Calendar'[Date]),
'Calendar'[Date] <= __currentMaxDate,
ALLSELECTED('Calendar'[Date])
)
var __shouldDisplay =
--check if the current period is fully contained in the future
NOT(__currentMinDate >= __previousmonth)
return
IF(__shouldDisplay, __cumulativevalue)

 

Many thanks in advance.

1 ACCEPTED SOLUTION
Anonymous
Not applicable

Cumulative E&A Wells (Prev Month) :=
VAR __currentMinDate = MIN ( 'Calendar'[Date] )
VAR __currentMaxDate = MAX ( 'Calendar'[Date] )
-- PREVIOUSMONTH is a function that returns a table
-- not a single value, hence you cannot use it in
-- a comparison like:
-- 'Calendar'[Date] <= __prevMonthEndDate VAR __prevMonthEndDate = EOMONTH( __currentMaxDate, -1 ) VAR __today = TODAY () VAR __cumulativevalue = CALCULATE ( COUNTROWS ( 'FM Full Export' ), DATESYTD ( 'Calendar'[Date] ), 'Calendar'[Date] <= __prevMonthEndDate, ALLSELECTED ( 'Calendar'[Date] ) ) VAR __shouldDisplay = NOT ( __currentMinDate >= __today ) RETURN IF ( __shouldDisplay, __cumulativevalue )

Best

Darek

View solution in original post

2 REPLIES 2
Anonymous
Not applicable

Cumulative E&A Wells (Prev Month) :=
VAR __currentMinDate = MIN ( 'Calendar'[Date] )
VAR __currentMaxDate = MAX ( 'Calendar'[Date] )
-- PREVIOUSMONTH is a function that returns a table
-- not a single value, hence you cannot use it in
-- a comparison like:
-- 'Calendar'[Date] <= __prevMonthEndDate VAR __prevMonthEndDate = EOMONTH( __currentMaxDate, -1 ) VAR __today = TODAY () VAR __cumulativevalue = CALCULATE ( COUNTROWS ( 'FM Full Export' ), DATESYTD ( 'Calendar'[Date] ), 'Calendar'[Date] <= __prevMonthEndDate, ALLSELECTED ( 'Calendar'[Date] ) ) VAR __shouldDisplay = NOT ( __currentMinDate >= __today ) RETURN IF ( __shouldDisplay, __cumulativevalue )

Best

Darek

Anonymous
Not applicable

@Anonymous - great stuff, thanks very much for the help.

 

Helpful resources

Announcements
FabCon Global Hackathon Carousel

FabCon Global Hackathon

Join the Fabric FabCon Global Hackathon—running virtually through Nov 3. Open to all skill levels. $10,000 in prizes!

September Power BI Update Carousel

Power BI Monthly Update - September 2025

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