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

Earn a 50% discount on the DP-600 certification exam by completing the Fabric 30 Days to Learn It challenge.

Reply
Anonymous
Not applicable

Dax mix of && and || in IF statement

Curious about how to mix && and || in IF statements. Ie- IF a=value1, b=value2, c=value3 OR d=value4 OR e=value5. In other words, if these three things are true or either of these other two things are true, than 1 else 0. Are parenthesis needed in some way to make this work?

 

Ex., convert OR's and And's in this statement (And's are already done but may need parenthesis changes): 

[Field] = IF(OR(OR(OR(RELATED('Dim - Product'[Class ID])=628 && RELATED('Dim - Product'[Subclass ID]) = 1519 && 'Fact - POS'[Config_Type] =7,RELATED('Dim - Product'[Class ID]) = 133),RELATED('Dim - Product'[Class ID])=265),RELATED('Dim - Product'[Class ID])=268)=True,1,0)

1 ACCEPTED SOLUTION
Phil_Seamark
Employee
Employee

Hi @Anonymous

 

Have a good look at the SWITCH statement.  It's really versatile.

 

The essence is :

Result = SWITCH (
           True() ,
            A = B && C = D , 1
            A = B || C = D , 2
            ---- ELSE ----
            999
           )

 

 


To learn more about DAX visit : aka.ms/practicalDAX

Proud to be a Datanaut!

View solution in original post

1 REPLY 1
Phil_Seamark
Employee
Employee

Hi @Anonymous

 

Have a good look at the SWITCH statement.  It's really versatile.

 

The essence is :

Result = SWITCH (
           True() ,
            A = B && C = D , 1
            A = B || C = D , 2
            ---- ELSE ----
            999
           )

 

 


To learn more about DAX visit : aka.ms/practicalDAX

Proud to be a Datanaut!

Helpful resources

Announcements
PBI_APRIL_CAROUSEL1

Power BI Monthly Update - April 2024

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