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

Find everything you need to get certified on Fabric—skills challenges, live sessions, exam prep, role guidance, and more. Get started

Reply
Jeanxyz
Post Prodigy
Post Prodigy

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
Europe Fabric Conference

Europe’s largest Microsoft Fabric Community Conference

Join the community in Stockholm for expert Microsoft Fabric learning including a very exciting keynote from Arun Ulag, Corporate Vice President, Azure Data.

Power BI Carousel June 2024

Power BI Monthly Update - June 2024

Check out the June 2024 Power BI update to learn about new features.

RTI Forums Carousel3

New forum boards available in Real-Time Intelligence.

Ask questions in Eventhouse and KQL, Eventstream, and Reflex.