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

Calling all Data Engineers! Fabric Data Engineer (Exam DP-700) live sessions are back! Starting October 16th. Sign up.

Reply
Anonymous
Not applicable

Combination of two DAX statements with IF statements for Conditional Formatting rules

Hey PBI Community,

 

I've got a few measures that I'm trying to combine into one so I can have a rule that checks values of 1 & 2, and colour values off that.

 

I have two that do the same thing, just checking different columns, for reference these are:

 

Checking highest result based of criteria, marking as 1 if result is greater than or equal to the criteria:

 

Highest =
VAR ThisResult =
    MAX (Query1[Result])
VAR Criteria=
    MAXX (
        ALLSELECTED (Query1[Result]),
        CALCULATE (
            MAX (Query1[Criteria])
        )
    )
RETURN
    IF (
        ThisResult >= Criteria,
        1,
        0
    )

 

 

Checks Range against Criteria, if the Range is greater than or equal to Criteria, then 1 else 0.

 

Range > Criteria=
VAR Criteria =
    MAXX (
        ALLSELECTED (Query1[Criteria]),
        CALCULATE (
            MAX (Query1[Criteria])
        )
    )
VAR Range =
    MAXX (
        ALLSELECTED (Query1[Range]),
        CALCULATE (
            MAX (Query1[Range])
        )
    )
RETURN
    IF (
        Range >= Criteria,
        1,
        0
    )

 

 

These both work with the data that I have, however you can't do a rule based on multiple measures (or so I am led to believe), so I am trying to make both work in the same measure.

 

I have psuedo that does what I was expecting but it cannot accept multiple IF statements, I have tried ELSE and a comma but I can't figure out if this is correct or not:

 

ExceedsCheck =
VAR ThisResult =
    MAX (Query1[Result])
VAR Criteria=
    MAXX (
        ALLSELECTED ( Query1[Criteria] ),
        CALCULATE (
            MAX ( Query1[Criteria] )
        )
    )
VAR Range=
    MAXX (
        ALLSELECTED ( Query1[Range] ),
        CALCULATE (
            MAX ( Query1[Range] )
        )
    )
RETURN
    IF (
        Range >= Criteria,
        1,
        0
    )
	IF (
		ThisResult >= Criteria, 
		2, 
		0
	)

 

 

EDIT: If both have are 1, then 2?

 

Thanks!

1 ACCEPTED SOLUTION

You can do this with if - if you want it to prioritise 1 over 2, then you go:

 

if (Range>=Criteria, 1,if(ThisResult>=Criteria, 2, 0))

 

If you want it to prioritise 2 over 1, then reverse the order which it looks at first.

View solution in original post

3 REPLIES 3
jthomson
Solution Sage
Solution Sage

Rather than having the false statement of one of the if statements being 0, stick the other if statement in there instead so it's nested into one statement. You'd need to decide which of 1 or 2 you want to show if both criteria are hit (assuming this is possible in your data model) 

Anonymous
Not applicable

Thanks @jthomson I've given this a go and understand where you are trying to advise. I don't think an IF statement is the best for this because there are three possible outcomes.

 

Are you aware of any DAX syntax that allows for three different outputs? I don't think you can nest an IF three times in DAX as it is true or false?

You can do this with if - if you want it to prioritise 1 over 2, then you go:

 

if (Range>=Criteria, 1,if(ThisResult>=Criteria, 2, 0))

 

If you want it to prioritise 2 over 1, then reverse the order which it looks at first.

Helpful resources

Announcements
FabCon Global Hackathon Carousel

FabCon Global Hackathon

Join the Fabric FabCon Global Hackathon—running virtually through Nov 3. Open to all skill levels. $10,000 in prizes!

September Power BI Update Carousel

Power BI Monthly Update - September 2025

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

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.