Execution order of AND/OR in case when statement
Hi everyone,
I am really confused about what is the order of executing AND/OR in case when statement and whether brackets work.
For example, what I want to achieve is:
(A AND B ) OR (A AND C) which means that I will select rows that can satisfy either AB or AC conditions.
(1) Question 1: Does brackets work if I have a case statement like this:
Case when (A AND B ) OR (A AND C) then 1 else 0 end.
Do I have to change to (For some reason, the following way can make my beast code too long, so I try to use the above method to put conditions in one statement):
Case
when A AND B then 1
when A AND B then 1
else 0
end
(2) Question 2:
If I have a statement like this:
Case when A AND B OR C AND D then 1 else 0 end
Does the order work like this:
((A AND B) Or C ) AND D ?
Thank you very much for your help in advance.
Best Answers
-
- (A AND B ) OR (A AND C) should work for what you want to achieve, as will your case statement with multiple conditions. Grouping different conditions using parenthesis is generally best practice if you are using just one line to avoid ambiguity.
- We need a little more information about what rows your want to include to be able to point you in the right direction
If you're ever unsure about how rows are being classified in case statements, I find that it's helpful to test multiple beast modes in a table card to see how each row is classified.
1 -
Regarding question 2 it will evaluate it in the orders of parenthesis first and then AND/OR equally going left to right so you're correct in that it will evaluate it like (A AND B) Or C ) AND D
**Was this post helpful? Click Agree or Like below**
**Did this solve your problem? Accept it as a solution!**1
Answers
-
- (A AND B ) OR (A AND C) should work for what you want to achieve, as will your case statement with multiple conditions. Grouping different conditions using parenthesis is generally best practice if you are using just one line to avoid ambiguity.
- We need a little more information about what rows your want to include to be able to point you in the right direction
If you're ever unsure about how rows are being classified in case statements, I find that it's helpful to test multiple beast modes in a table card to see how each row is classified.
1 -
Regarding question 2 it will evaluate it in the orders of parenthesis first and then AND/OR equally going left to right so you're correct in that it will evaluate it like (A AND B) Or C ) AND D
**Was this post helpful? Click Agree or Like below**
**Did this solve your problem? Accept it as a solution!**1 -
Thanks all for the answers and explanations.
0
Categories
- All Categories
- 1.8K Product Ideas
- 1.8K Ideas Exchange
- 1.6K Connect
- 1.2K Connectors
- 300 Workbench
- 6 Cloud Amplifier
- 9 Federated
- 2.9K Transform
- 102 SQL DataFlows
- 626 Datasets
- 2.2K Magic ETL
- 3.9K Visualize
- 2.5K Charting
- 753 Beast Mode
- 61 App Studio
- 41 Variables
- 692 Automate
- 177 Apps
- 456 APIs & Domo Developer
- 49 Workflows
- 10 DomoAI
- 38 Predict
- 16 Jupyter Workspaces
- 22 R & Python Tiles
- 398 Distribute
- 115 Domo Everywhere
- 276 Scheduled Reports
- 7 Software Integrations
- 130 Manage
- 127 Governance & Security
- 8 Domo Community Gallery
- 38 Product Releases
- 11 Domo University
- 5.4K Community Forums
- 40 Getting Started
- 30 Community Member Introductions
- 110 Community Announcements
- 4.8K Archive