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

Measure Optimization - Nesting IF inside filter section of calculate

I am trying to optimize this lagging  measure.  The following works, and gives me the desired outcome. Basically, if the month interval is 12 (December), return the first filter.  If not, return the second.  The basis of the  measure is to look at the selected month (determined in a slicer), and then return the values for the next month.

 

 

 

 

 

NextMonthJobsStartingTest = 
IF (
    SELECTEDVALUE ( 'Calendar'[MonthInt] ) = 12,
    CALCULATE (
        [SUMTotalAmt],
        FILTER (
            Sales,
            Sales[ProjectedStartDateMonthInt] = 1
                && Sales[ProjectedStartDateYear]
                    = SELECTEDVALUE ( 'Calendar'[Year] ) + 1
        )
    ),
    CALCULATE (
        [SUMTotalAmt],
        FILTER (
            Sales,
            Sales[ProjectedStartDateMonthInt]
                = SELECTEDVALUE ( 'Calendar'[MonthInt] ) + 1
                && Sales[ProjectedStartDateYear] = SELECTEDVALUE ( 'Calendar'[Year] )
        )
    )
)

 

 

 

 

 

I'm trying to parse this down and make it more efficient with the following.

 

 

 

 

NextMonthJobsStartingTest2 = 
CALCULATE (
    [SUMTotalAmt],
    IF (
        SELECTEDVALUE ( 'Calendar'[MonthInt] ) = 12,
        FILTER (
            Sales,
            Sales[ProjectedStartDateMonthInt] = 1
                && Sales[ProjectedStartDateYear]
                    = SELECTEDVALUE ( 'Calendar'[Year] ) + 1
        ),
        FILTER (
            Sales,
            Sales[ProjectedStartDateMonthInt]
                = SELECTEDVALUE ( 'Calendar'[MonthInt] ) + 1
                && Sales[ProjectedStartDateYear] = SELECTEDVALUE ( 'Calendar'[Year] )
        )
    )
)

 

 

 

 

 

I recieve the following error message:

 

 

Screenshot1.PNG

 

It appears that the measure doesn't like using IF() to determine which filter to select... What other options can I use?  Also, is there a better way to trim down this measure?

 

TIA

1 ACCEPTED SOLUTION
Vera_33
Resident Rockstar
Resident Rockstar

Hi @Anonymous 

 

You need to determin the next month period, try this way, assume you have Date column in Calendar

NextMonthJobsStartingTest = 
VAR CurDate = DATE(SELECTEDVALUE ( 'Calendar'[Year] ),SELECTEDVALUE( 'Calendar'[MonthInt] ),1)
VAR MinDate = EDATE(CurDate,1)
VAR MaxDate = EDATE(CurDate,2)
RETURN
SUMX(FILTER(ALL('Calendar'),'Calendar'[Date]>=MinDate&&'Calendar'[Date]<MaxDate),[SUMTotalAmt])

 

View solution in original post

2 REPLIES 2
Vera_33
Resident Rockstar
Resident Rockstar

Hi @Anonymous 

 

You need to determin the next month period, try this way, assume you have Date column in Calendar

NextMonthJobsStartingTest = 
VAR CurDate = DATE(SELECTEDVALUE ( 'Calendar'[Year] ),SELECTEDVALUE( 'Calendar'[MonthInt] ),1)
VAR MinDate = EDATE(CurDate,1)
VAR MaxDate = EDATE(CurDate,2)
RETURN
SUMX(FILTER(ALL('Calendar'),'Calendar'[Date]>=MinDate&&'Calendar'[Date]<MaxDate),[SUMTotalAmt])

 

Anonymous
Not applicable

@Vera_33.  Thanks so much.  This did work.  The only change I added was to use 'Sales'[ProjectedStartDate] in place of 'Calendar'[Date].  I need to filter based on the Projected Start Date...

 

As well, I had to drop the All('Calendar') piece of the filter.  Any idea why that would be?

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.