Application scope
The dynamic discount formula builder applies to the following discount types:- Order discount
- Product discount
- Reward
- Fixed
- Proportional
Context specific
The operators and operands in the dynamic formula builder depend on the context of the formula, such as the discount effect and other factors. Some of the operators and operands will not be available based on the specific configuration.Formula builder
You can use the Formula builder utility with step-by-step dialogs to build the formula from element building blocks.Build formula
Build your formula using the formula builder by choosing a type of operand followed by an operator. Click the X button to delete a number or expression and the + button to add a number or expression.
Expression output
You can view and edit the dynamic formula through a mathematical expression using operands and operators. Click Save once you have finished defining your dynamic formula.Operand reference
You can see the discount values that you can create using different discount operands in the following table.Metadata and base operands
| Operand | Definition | Example |
|---|---|---|
| Number | Value is a Number. | 2 |
| Text | Value is a String. | Unique string of alphanumeric characters. |
| Order metadata | Value is an order metadata attribute of type Number or String. | ORDER_METADATA("day_of_week") |
| Voucher metadata | Value is a voucher metadata attribute of type Number or String. Available in dynamic discount formulas only. | REDEEMABLE_METADATA("active_on_calendar_month") |
| Customer metadata | Value is a customer metadata attribute of type Number or String. | CUSTOMER_METADATA("customer_life_time_value") |
| Redemption metadata | Value is a redemption metadata attribute of type Number or String. Available in dynamic discount formulas only. | REDEMPTION_METADATA("store_list") |
| Publication metadata | Value is a publication metadata attribute of type Number or String. Available in dynamic discount formulas only. | PUBLICATION_METADATA("year") |
| Promotion tier metadata | Value is an order metadata attribute of type Number or String. Available in dynamic discount formulas only (promotion). | REDEEMABLE_METADATA("membership_duration") |
Expression functions
| Operand | Definition | Example |
|---|---|---|
| Brackets | Groups expression elements together; i.e. adds parentheses to your formula. | (10 - ORDER_METADATA("number_of_store_visits")) |
| Min | Lowest value in a range | MIN(PUBLICATION_METADATA("year"); CUSTOMER_METADATA("customer_life_time_value")) |
| Max | Highest value in a range | MAX(PUBLICATION_METADATA("year"); CUSTOMER_METADATA("customer_life_time_value")) |
| Power | A number raised to a power; defines the base and exponent. | POW(ORDER_METADATA("number_of_store_visits");2) |
| Round | Round a number to a specified number of digits. Positive precision refers to a decimal place indicator. Negative precision indicates an integer place indicator. | ROUND(CUSTOMER_METADATA("customer_life_time_value");1) |
| Floor | Round down to a specified number of digits. | FLOOR(CUSTOMER_METADATA("customer_life_time_value");1) |
| Ceil | Round up to a specified number of digits. | CEIL(CUSTOMER_METADATA("customer_life_time_value");1) |
| If | Value based on a logical expression; defines the logical test value, value if expression is true and value if expression is false. | IF(ORDER_METADATA("number_of_store_visits") > 5;10;3) |
| Default to | Returns the first non-null value of range. | DEFAULT_TO(REDEMPTION_METADATA("store_list") / 2;5) |
Order item operands (product discount only)
| Operand | Definition |
|---|---|
| ORDER_ITEM_PRICE | Returns order item price. |
| ORDER_ITEM_AMOUNT | Returns order item amount; for stacked discounts, returns the original amount without any modifications due to other discounts. |
| ORDER_ITEM_SUBTOTAL | Returns order item subtotal; for stacked discounts, each additional discount is based on the result obtained after calculating the previous discount. |
| ORDER_ITEM_UNITS_QUANTITY | Returns order item quantity. |
| ORDER_ITEM_METADATA(“Size”) | Returns order item metadata. |
| ORDER_ITEM_PRODUCT_METADATA(“category”) | Returns order item product metadata. |
Order-level operands
| Operand | Definition |
|---|---|
| ORDER_AMOUNT | Returns the order total value, whole cart value. |
| ORDER_ITEMS_QUANTITY | Returns the item count. |
| ORDER_UNITS_QUANTITY | Returns the sum of the units ordered. |
Cheapest order item operands
| Operand | Definition |
|---|---|
| CHEAPEST_ORDER_ITEM_PRICE | Returns the price of the cheapest line item in the order. |
| CHEAPEST_ORDER_ITEM_AMOUNT | Returns the amount of the cheapest line items in the order; for stacked discounts, returns the original amount without any modifications due to other discounts. |
| CHEAPEST_ORDER_ITEM_SUBTOTAL | Returns the subtotal of the cheapest line items in the order; for stacked discounts, each additional discount is based on the result obtained after calculating the previous discount. |
| CHEAPEST_ORDER_ITEM_UNITS_QUANTITY | Returns total units of the cheapest order line items. |
| CHEAPEST_ORDER_ITEM_METADATA(“Size”) | Returns the cheapest order item metadata of type Number or String. |
| CHEAPEST_ORDER_ITEM_PRODUCT_METADATA(“category”) | Returns the cheapest order item product metadata. |
Most expensive order item operands
| Operand | Definition |
|---|---|
| MOST_EXPENSIVE_ORDER_ITEM_PRICE | Returns the price of the most expensive line item in the order. |
| MOST_EXPENSIVE_ORDER_ITEM_AMOUNT | Returns the amount of the most expensive line items in the order; for stacked discounts, returns the original amount without any modifications due to discounts. |
| MOST_EXPENSIVE_ORDER_ITEM_SUBTOTAL | Returns the subtotal of the most expensive line items in the order; for stacked discounts, each additional discount is based on the result obtained after calculating the previous discount. |
| MOST_EXPENSIVE_ORDER_ITEM_UNITS_QUANTITY | Returns the total units of the most expensive order line items. |
| MOST_EXPENSIVE_ORDER_ITEM_METADATA(“Size”) | Returns the most expensive order item metadata of type Number or String. |
| MOST_EXPENSIVE_ORDER_ITEM_PRODUCT_METADATA(“category”) | Returns the most expensive order item product metadata. |
The Cheapest & Most Expensive Order Item
How are the cheapest and most expensive order items found if there are multiple items with the same price?Cheapest order item
- First, the formula tries to find the order item with the cheapest price. If there is one item, the formula returns this item. Otherwise, it proceeds to step 2.
- If there are n items that have the same cheapest price, from this n, the formula finds the items with the lowest subtotal. If there is only one item, the formula returns this item. Otherwise, if there are many items, it proceeds to step 3.
- Finally, it returns the first item from the list of the cheapest items with the lowest subtotal.
Most expensive order item
- First, the formula tries to find the order item with the most expensive price. If there is one item, the formula returns this item. Otherwise, it proceeds to step 2.
- If there are n items that have the same most expensive price, from this n, the formula finds the items with the lowest subtotal. If there is only one item, the formula returns this item. Otherwise, if there are many items, it proceeds to step 3.
- Finally, it returns the first item from the list of the most expensive items with the lowest subtotal.
Operator reference
Number operators
Here are the discount formula operators you can choose from for properties of Number type.Add (+)
Adds numbers or expressions. Example with missing metadata property defaulting to fallback value:number_of_store_visitsFallback value: 10%
Subtract (-)
Subtracts numbers or expressions. Give a customer a percent off for every year since they first became a customer.customer_life_time_value: 2012 Calculated dynamic discount value: 10%
Fallback value: 10%
Multiply (x)
Multiplies numbers or expressions. Give a customer a discount proportional to the day of the week if the week is defined as: Sunday - 0Monday - 1
Tuesday - 2
Wednesday - 3
Thursday - 4
Friday - 5
Saturday - 6
Divide (÷)
Divides numbers or expressions. Give a customer an eighth for every month the customer was active.Modulo (%)
Returns the remainder after division. Give a customer a certain number of free items based on a custom formula.allowed_free_units: 9
remainder: 1 Calculated dynamic discount value: 1 Free item
Fallback value: 1 Free item

