Features
Formulas allow you to perform basic mathematical calculations directly within your expressions, using standard arithmetic operators. This is useful for creating custom calculations, comparing metrics relatively, or defining dynamic thresholds in variables.
+
Addition: Adds two numeric values.
Example: bid > cpc(7d) + 0.10
-
Subtraction: Subtracts the second numeric value from the first.
Example: budget - spend(1d) < 2.00
*
Multiplication: Multiplies two numeric values.
Example: acos(30d) < target acos * 0.8
/
Division: Divides the first numeric value by the second. Useful for calculating ratios. Handle potential division by zero errors (see Error Handling).
Example: sales(14d) / clicks(14d) > 0.75
%
The %
symbol acts as a shorthand for dividing by 100. It is not a Modulo operator in Formulas. When placed after a number, that number is treated as a percentage and converted to its decimal equivalent for calculations.
Examples:
acos(30d) > 45%
is equivalent to acos(30d) > 0.45
let $target_increase = 10%;
bid * (1 + $target_increase)
This is equivalent to bid * (1 + 0.10)
Formulas follow the standard mathematical order of operations (similar to PEMDAS/BODMAS):
*
, Division /
, are evaluated first, from left to right.+
, Subtraction -
are evaluated next, from left to right.Example:
spend(7d) / 7 * 1.1 > 10.00
This is evaluated as (spend(7d) / 7) * 1.1 > 10.00
. The division happens first, then the multiplication.
Use parentheses to override the default order or clarify calculations, just like in standard math.
Example:
// Calculate average daily spend over 14 days
let $avg_daily_spend = spend(14d) / 14;
// Check if budget is less than 110% of average daily spend
budget < (spend(14d) / 14) * 1.1
While the parentheses around spend(14d) / 14
aren't strictly necessary due to precedence, they can improve readability.
You can freely combine arithmetic operations with both static properties (like bid
, budget
) and time-based properties (like clicks(30d)
, sales(7d..14d)
).
Example:
let $target_bid = (sales(30d) / clicks(30d)) * target acos * 0.9;
// Calc target bid based on RPC & target ACOS (with 10% cushion)
bid < $target_bid
Remember that operations require compatible Data Types (primarily Numbers). Refer to the Syntax Reference for details on properties and functions.
© Merch Jar LLC