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
UsePowerBI
Post Prodigy
Post Prodigy

In what order are nested conditions evaluated?

Hello

 

First, I would like to say that the DAX limit of AND/OR functions to accept only two conditions, while Excel accepts unlimited conditions, is extremely inconvenient. Is there a fix for this? Nesting conditions makes the whole expression very complex.

 

Secondly, in what order are nested conditions evaluated? I had the impression that they are evaluated from left to right, e.g.:

 

IF(condition1,IF(condition2,do1,do2)) = I thought that condition1 is evaluated first and then condition2.

 

Is this the case? Because I read 'If a DAX calculation is nested, theinnermost function is evaluated first.' which is very confusing.

 

Thanks!

1 ACCEPTED SOLUTION
parry2k
Super User
Super User

@UsePowerBI first thing first, for multiple AND and OR , you can use && for AND and || for OR

 

IF (  x = 1 && y = 2 &&  z = 3 && p = "x", "abc", "xyz" )

 

 

IF (  x = 1 || y = 2 || z = 3 || p = "x", "abc", "xyz" )

 

on 2nd question, left to right, condition1 and then condition 2

 

Would appreciate Kudos 🙂 if my solution helped.

 



Subscribe to the @PowerBIHowTo YT channel for an upcoming video on List and Record functions in Power Query!!

Learn Power BI and Fabric - subscribe to our YT channel - Click here: @PowerBIHowTo

If my solution proved useful, I'd be delighted to receive Kudos. When you put effort into asking a question, it's equally thoughtful to acknowledge and give Kudos to the individual who helped you solve the problem. It's a small gesture that shows appreciation and encouragement! ❤


Did I answer your question? Mark my post as a solution. Proud to be a Super User! Appreciate your Kudos 🙂
Feel free to email me with any of your BI needs.

View solution in original post

4 REPLIES 4
v-jayw-msft
Community Support
Community Support

Hi @UsePowerBI ,

 

For the first question, you can use "&&" / "||" instead.

AND(AND(AND(OR(OR(OR(1=1,2=2),3=3),4=4),5=5),6=6),7=7)
(1=1||2=2||3=3||4=4)&&5=5&&6=6&&7=7

For the second question, logic of IF() function is from left to right and logic of AND() / OR() function is from inside to outside.

 

Best Regards,

Jay

Community Support Team _ Jay Wang

If this post helps, then please consider Accept it as the solution to help the other members find it more quickly.

Community Support Team _ Jay
If this post helps, then please consider Accept it as the solution
to help the other members find it.
amitchandak
Super User
Super User

First The first if the condition will be evaluated, 

TRUE - Condition is true will process

False - Condition is true will process

 

https://docs.microsoft.com/en-us/dax/if-function-dax

 

Appreciate your Kudos. In case, this is the solution you are looking for, mark it as the Solution. In case it does not help, please provide additional information and mark me with @
Thanks. My Recent Blog -
https://community.powerbi.com/t5/Community-Blog/HR-Analytics-Active-Employee-Hire-and-Termination-tr...
https://community.powerbi.com/t5/Community-Blog/Power-BI-Working-with-Non-Standard-Time-Periods/ba-p...
https://community.powerbi.com/t5/Community-Blog/Comparing-Data-Across-Date-Ranges/ba-p/823601

Stachu
Community Champion
Community Champion

Regarding your first question - you can use multiple conditions with && for AND and || for OR, e.g.

(true && true && false)

  returns false

(false || true || false)

returns true 

 

to my knowledge your intuition regarding the order of conditions evaluations is correct

the statement about the inner calculation being evalauted first is also true, but it refers to the filter context, which is very different from conditions, see more detailed explanation here:

https://www.sqlbi.com/articles/order-of-evaluation-in-calculate-parameters/



Did I answer your question? Mark my post as a solution!
Thank you for the kudos 🙂

parry2k
Super User
Super User

@UsePowerBI first thing first, for multiple AND and OR , you can use && for AND and || for OR

 

IF (  x = 1 && y = 2 &&  z = 3 && p = "x", "abc", "xyz" )

 

 

IF (  x = 1 || y = 2 || z = 3 || p = "x", "abc", "xyz" )

 

on 2nd question, left to right, condition1 and then condition 2

 

Would appreciate Kudos 🙂 if my solution helped.

 



Subscribe to the @PowerBIHowTo YT channel for an upcoming video on List and Record functions in Power Query!!

Learn Power BI and Fabric - subscribe to our YT channel - Click here: @PowerBIHowTo

If my solution proved useful, I'd be delighted to receive Kudos. When you put effort into asking a question, it's equally thoughtful to acknowledge and give Kudos to the individual who helped you solve the problem. It's a small gesture that shows appreciation and encouragement! ❤


Did I answer your question? Mark my post as a solution. Proud to be a Super User! Appreciate your Kudos 🙂
Feel free to email me with any of your BI needs.

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.

Top Solution Authors