Combining Conditions: Boolean Logic & Grouping

Simple filters often involve a single condition (e.g., clicks(7d) > 10). However, the real power of Formulas comes from combining multiple conditions using Boolean Logic and controlling the order of evaluation with Grouping.

Logical Operators

These operators allow you to link multiple conditions together:

and

Returns true only if all conditions connected by and are true. Used to narrow down results by requiring multiple criteria to be met simultaneously.

Example:

// Find campaigns that are enabled and have high ACOS
state = "enabled" and acos(30d) > 45%

or

Returns true if at least one of the conditions connected by or is true. Used to broaden results by allowing different criteria to satisfy the rule.

Example:

// Find targets that are either paused or have had zero clicks recently
state = "paused" or clicks(14d) = 0

Operator Precedence

When you mix and and or in the same expression without parentheses, the system follows a specific order of operations:

and is evaluated BEFORE or.

Example:

// Find enabled items with high spend OR items with zero orders
state = "enabled" and spend(30d) > 50 or orders(30d) = 0

This is interpreted by the system as:

((state = "enabled" and spend(30d) > 50)) or (orders(30d) = 0)

It first checks if the item is enabled and has high spend. If that entire combination is true, the whole expression is true. If not, it then checks if orders are zero.

Grouping with Parentheses

To override the default precedence or clarify complex logic, use parentheses (). Expressions inside parentheses are evaluated first.

Example: Changing the Logic

Let's say you want to find items that are enabled, and they meet either the high spend condition or the zero order condition. You need parentheses:

// Find enabled items that ALSO have (high spend OR zero orders)
state = "enabled" and (spend(30d) > 50 or orders(30d) = 0)

This ensures the or condition is evaluated first, and the result is then combined with the state = "enabled" condition using and.

Complex Example:

// High ACOS targets OR (low CTR targets that have actually spent money)
(acos(60d) > 50%) or (ctr(60d) < 0.2% and spend(60d) > 5.00)

Always use parentheses when mixing and and or if the default precedence doesn't match your intended logic. It makes the formula much clearer and prevents errors.

PREVIOUS ARTICLE
NEXT ARTICLE