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

Join us for an expert-led overview of the tools and concepts you'll need to become a Certified Power BI Data Analyst and pass exam PL-300. Register now.

Reply
datagoblin77
Frequent Visitor

A function 'MAX' has been used in a True/False expression that is used as a table filter expression.

I am trying to create a card that shows the reduction in emissions for a school. I created a measure for total beef purchases:

Total Emissions:= SUM(tSustainability_FactBeefEmissions[CO2 (tonnes)])

Then I created a percentage measure:

Emission difference (pecentage):=
Var EarliestData = CALCULATE([Total Emissions], tSustainability_FactBeefEmissions[Order] = MIN(tSustainability_FactBeefEmissions[Order]))
VAR LatestData = CALCULATE([Total Emissions], tSustainability_FactBeefEmissions[Order] =Max(tSustainability_FactBeefEmissions[Order]))

RETURN
FORMAT( (LatestData - EarliestData)/EarliestData, "0%")


The measure returns the right value in visual studio. When I deploy the solution in pbi desktop I get the message that a MIN has been used in a true/false expression. How do I make dax pick the value in the emission column that is corresponding to the lowest value in the order column?

 

1 ACCEPTED SOLUTION
mark_endicott
Super User
Super User

@datagoblin77 - By putting the MIN and MAX next to an = you turn it into a TRUE/FALSE expression. 

 

You should try this:

 

 

 

VAR _min =
    MIN ( tSustainability_FactBeefEmissions[Order] )
VAR _max =
    MAX ( tSustainability_FactBeefEmissions[Order] )
VAR min_Emission =
    CALCULATE (
        [Total Emissions],
        KEEPFILTERS ( tSustainability_FactBeefEmissions[Order] = _min )
    )
VAR max_Emission =
    CALCULATE (
        [Total Emissions],
        KEEPFILTERS ( tSustainability_FactBeefEmissions[Order] = _max )
    )
RETURN
    DIVIDE ( ( max_Emission - min_Emission ), min_Emission, 0 )

 

 

 

KEEPFILTERS is used to maintain this filter context, but not overwrite any others, which if you use this calculation elsewhere will prevent a confusing output. 

 

DIVIDE is more optimal than using "/" and it helps with divide by 0 errors which "/" will not. 

 

I have also removed your FORMAT expression, because this is turning the figure presented into a string. By using the Power BI UI to make this a % you will have much more freedom, and can use this calculation for conditional formatting etc. You can do this by selecting the measure and selecting Percentage from the Format options on Measure Tools:

 

mark_endicott_0-1717166931454.png

If this works for you, please mark it as the solution!

View solution in original post

4 REPLIES 4
mark_endicott
Super User
Super User

@datagoblin77 - By putting the MIN and MAX next to an = you turn it into a TRUE/FALSE expression. 

 

You should try this:

 

 

 

VAR _min =
    MIN ( tSustainability_FactBeefEmissions[Order] )
VAR _max =
    MAX ( tSustainability_FactBeefEmissions[Order] )
VAR min_Emission =
    CALCULATE (
        [Total Emissions],
        KEEPFILTERS ( tSustainability_FactBeefEmissions[Order] = _min )
    )
VAR max_Emission =
    CALCULATE (
        [Total Emissions],
        KEEPFILTERS ( tSustainability_FactBeefEmissions[Order] = _max )
    )
RETURN
    DIVIDE ( ( max_Emission - min_Emission ), min_Emission, 0 )

 

 

 

KEEPFILTERS is used to maintain this filter context, but not overwrite any others, which if you use this calculation elsewhere will prevent a confusing output. 

 

DIVIDE is more optimal than using "/" and it helps with divide by 0 errors which "/" will not. 

 

I have also removed your FORMAT expression, because this is turning the figure presented into a string. By using the Power BI UI to make this a % you will have much more freedom, and can use this calculation for conditional formatting etc. You can do this by selecting the measure and selecting Percentage from the Format options on Measure Tools:

 

mark_endicott_0-1717166931454.png

If this works for you, please mark it as the solution!

Thank you!

 

Happy to help!

BeaBF
Super User
Super User

@datagoblin77 try with:

Emission difference (percentage):=
VAR EarliestOrder = CALCULATE(MIN(tSustainability_FactBeefEmissions[Order]))
VAR EarliestEmission = CALCULATE([Total Emissions], tSustainability_FactBeefEmissions[Order] = EarliestOrder)

VAR LatestOrder = CALCULATE(MAX(tSustainability_FactBeefEmissions[Order]))
VAR LatestEmission = CALCULATE([Total Emissions], tSustainability_FactBeefEmissions[Order] = LatestOrder)

RETURN
FORMAT( (LatestEmission - EarliestEmission)/EarliestEmission, "0%")

Helpful resources

Announcements
Join our Fabric User Panel

Join our Fabric User Panel

This is your chance to engage directly with the engineering team behind Fabric and Power BI. Share your experiences and shape the future.

June 2025 Power BI Update Carousel

Power BI Monthly Update - June 2025

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

June 2025 community update carousel

Fabric Community Update - June 2025

Find out what's new and trending in the Fabric community.