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
- 300 Workbench
- 6 Cloud Amplifier
- 8 Federated
- 2.9K Transform
- 100 SQL DataFlows
- 616 Datasets
- 2.2K Magic ETL
- 3.9K Visualize
- 2.5K Charting
- 738 Beast Mode
- 56 App Studio
- 40 Variables
- 685 Automate
- 176 Apps
- 452 APIs & Domo Developer
- 47 Workflows
- 10 DomoAI
- 36 Predict
- 15 Jupyter Workspaces
- 21 R & Python Tiles
- 394 Distribute
- 113 Domo Everywhere
- 275 Scheduled Reports
- 6 Software Integrations
- 123 Manage
- 120 Governance & Security
- 8 Domo Community Gallery
- 38 Product Releases
- 10 Domo University
- 5.4K Community Forums
- 40 Getting Started
- 30 Community Member Introductions
- 108 Community Announcements
- 4.8K Archive