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! Request now

Reply
Jeanxyz
Power Participant
Power Participant

max() formula doesn't take filter context in the measure

I have a project baseline fact table, looks like below. I need to create a measure will will add out the baseline of each project (column [max workdays]) by customer and project responsible person and the filtered yearmonth-1month.  The baseline of each project may change over time, so it's important that the measure takes filtered yearmonth into consideration. 

 

Below is the measure I have created. It looks the max(Fact_project_baseline_summarize[max workdays] part doesn't take into consideration the filter() condition I have created. Can someone help? The correct total baseline of customer MBC should be 1181 days.

 

I have also created a sample power bi file.

https://www.dropbox.com/s/gjmqdzciksqjhqc/Project%20test.pbix?dl=0

 

****************************************************************

total baseline_closed_month2 =
Var SelectedMonth = month(max(Dim_Date[Date]))
Var SelectedYear = year(max(Dim_Date[Date]))
VAR cm = IF(SelectedMonth>1,SelectedMonth-1,12+(SelectedMonth-1))
VAR cy = IF(SelectedMonth>1,SelectedYear,SelectedYear-1)
Var Baseline_closed_month2 = sumx(filter(Fact_project_baseline_summarize,Fact_project_baseline_summarize[Baseline_Date]=date(cy,cm,1)),max(Fact_project_baseline_summarize[max workdays]))
return
Baseline_closed_month2

*******************************************************************************************

project baseline.PNG

1 ACCEPTED SOLUTION
AlexisOlson
Super User
Super User

You need to wrap the MAX in CALCULATE to do the context transition.

 

total baseline_closed_month2 =
VAR CurrDate = MAX ( Dim_Date[Date] )
VAR PrevMonthStart = EOMONTH ( CurrDate, -2 ) + 1
VAR Baseline_closed_month2 =
    SUMX (
        FILTER (
            Fact_project_baseline_summarize,
            Fact_project_baseline_summarize[Baseline_Date] = PrevMonthStart
        ),
        CALCULATE ( MAX ( Fact_project_baseline_summarize[max workdays] ) )
    )
RETURN
    Baseline_closed_month2

 

I think you could probably simplify this assuming each project doesn't have more than one row per baseline date.

total baseline_closed_month2 =
VAR CurrDate = MAX ( Dim_Date[Date] )
VAR PrevMonthStart = EOMONTH ( CurrDate, -2 ) + 1
RETURN
    CALCULATE (
        SUM ( Fact_project_baseline_summarize[max workdays] ),
        Fact_project_baseline_summarize[Baseline_Date] = PrevMonthStart
    )

View solution in original post

1 REPLY 1
AlexisOlson
Super User
Super User

You need to wrap the MAX in CALCULATE to do the context transition.

 

total baseline_closed_month2 =
VAR CurrDate = MAX ( Dim_Date[Date] )
VAR PrevMonthStart = EOMONTH ( CurrDate, -2 ) + 1
VAR Baseline_closed_month2 =
    SUMX (
        FILTER (
            Fact_project_baseline_summarize,
            Fact_project_baseline_summarize[Baseline_Date] = PrevMonthStart
        ),
        CALCULATE ( MAX ( Fact_project_baseline_summarize[max workdays] ) )
    )
RETURN
    Baseline_closed_month2

 

I think you could probably simplify this assuming each project doesn't have more than one row per baseline date.

total baseline_closed_month2 =
VAR CurrDate = MAX ( Dim_Date[Date] )
VAR PrevMonthStart = EOMONTH ( CurrDate, -2 ) + 1
RETURN
    CALCULATE (
        SUM ( Fact_project_baseline_summarize[max workdays] ),
        Fact_project_baseline_summarize[Baseline_Date] = PrevMonthStart
    )

Helpful resources

Announcements
November Power BI Update Carousel

Power BI Monthly Update - November 2025

Check out the November 2025 Power BI update to learn about new features.

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!

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.

Top Solution Authors