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

Register now to learn Fabric in free live sessions led by the best Microsoft experts. From Apr 16 to May 9, in English and Spanish.

Reply
damonkimble
Frequent Visitor

Nested IF Statement with logical or condition

Hi All!

I created nested if statements that contain OR conditions. Example: IF a = 1 or b = 1, then "Pass" IF "a=2 or b=2", then "Fail", IF blank(), then "TBD". The problem is my result has "Pass" or "Fail", but "TBD" does not appear even though I have a lot of blanks.  For some reason, the blanks are coming as "Pass" but should be "TBD". Please see the screenshot and dax code below - thank you all!

damonkimble_0-1625670000700.png

 

 

FTC_Fail_Pass =
IF(Booking[brs_followupreason (groups)] = "Customers did not show up for meet"
|| Booking[brs_followupreason (groups)] = "Branch staff turned me away"
||Booking[brs_followupreason (groups)] = "Site not ready"
|| Booking[brs_followupreason (groups)] = "Vendor did not show up for meet",
"Fail",
IF( Booking[brs_followupreason (groups)] <> "Customers did not show up for meet"
|| Booking[brs_followupreason (groups)] <> "Branch staff turned me away"
|| Booking[brs_followupreason (groups)] <> "Site not ready"
|| Booking[brs_followupreason (groups)] <> "Vendor did not show up for meet"
|| Booking[brs_followupreason (groups)] <> "Need Part",
"Pass",
IF(Booking[brs_followupreason (groups)] = BLANK(),
"TBD"
)
)
)
1 ACCEPTED SOLUTION
AlexisOlson
Super User
Super User

Note that the logical statement "a <> 1 || a <>2" is always true since if a <> 1 then the first case hold and, otherwise, if a = 1, then a <> 2 and the second case holds. This is why you never get to the "TBD" condition.

 

The negation of "a = 1 || a = 2" is not "a <> 1 || a <> 2" but rather "NOT ( a =1 || a = 2 )" = "a <> 1 && a <> 2".

 

I'd recommend rewriting your logic more compactly like this:

FTC_Fail_Pass =
IF (
    ISBLANK ( Booking[brs_followupreason (groups)] ),
    "TBD",
    IF (
        Booking[brs_followupreason (groups)]
            IN {
            "Customers did not show up for meet",
            "Branch staff turned me away",
            "Site not ready",
            "Vendor did not show up for meet"
        },
        "Fail",
        "Pass"
    )
)

View solution in original post

1 REPLY 1
AlexisOlson
Super User
Super User

Note that the logical statement "a <> 1 || a <>2" is always true since if a <> 1 then the first case hold and, otherwise, if a = 1, then a <> 2 and the second case holds. This is why you never get to the "TBD" condition.

 

The negation of "a = 1 || a = 2" is not "a <> 1 || a <> 2" but rather "NOT ( a =1 || a = 2 )" = "a <> 1 && a <> 2".

 

I'd recommend rewriting your logic more compactly like this:

FTC_Fail_Pass =
IF (
    ISBLANK ( Booking[brs_followupreason (groups)] ),
    "TBD",
    IF (
        Booking[brs_followupreason (groups)]
            IN {
            "Customers did not show up for meet",
            "Branch staff turned me away",
            "Site not ready",
            "Vendor did not show up for meet"
        },
        "Fail",
        "Pass"
    )
)

Helpful resources

Announcements
Microsoft Fabric Learn Together

Microsoft Fabric Learn Together

Covering the world! 9:00-10:30 AM Sydney, 4:00-5:30 PM CET (Paris/Berlin), 7:00-8:30 PM Mexico City

PBI_APRIL_CAROUSEL1

Power BI Monthly Update - April 2024

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

April Fabric Community Update

Fabric Community Update - April 2024

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