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

Be one of the first to start using Fabric Databases. View on-demand sessions with database experts and the Microsoft product team to learn just how easy it is to get started. Watch now

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
Las Vegas 2025

Join us at the Microsoft Fabric Community Conference

March 31 - April 2, 2025, in Las Vegas, Nevada. Use code MSCUST for a $150 discount!

Dec Fabric Community Survey

We want your feedback!

Your insights matter. That’s why we created a quick survey to learn about your experience finding answers to technical questions.

ArunFabCon

Microsoft Fabric Community Conference 2025

Arun Ulag shares exciting details about the Microsoft Fabric Conference 2025, which will be held in Las Vegas, NV.

December 2024

A Year in Review - December 2024

Find out what content was popular in the Fabric community during 2024.