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.5K Connect
- 1.2K Connectors
- 297 Workbench
- 6 Cloud Amplifier
- 8 Federated
- 2.9K Transform
- 100 SQL DataFlows
- 614 Datasets
- 2.2K Magic ETL
- 3.8K Visualize
- 2.5K Charting
- 729 Beast Mode
- 53 App Studio
- 40 Variables
- 677 Automate
- 173 Apps
- 451 APIs & Domo Developer
- 45 Workflows
- 8 DomoAI
- 34 Predict
- 14 Jupyter Workspaces
- 20 R & Python Tiles
- 394 Distribute
- 113 Domo Everywhere
- 275 Scheduled Reports
- 6 Software Integrations
- 121 Manage
- 118 Governance & Security
- Domo Community Gallery
- 32 Product Releases
- 10 Domo University
- 5.4K Community Forums
- 40 Getting Started
- 30 Community Member Introductions
- 108 Community Announcements
- 4.8K Archive