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