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

Compete to become Power BI Data Viz World Champion! First round ends August 18th. Get started.

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
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.