Skip to main content
The dynamic formula builder defines how discount or loyalty point values are calculated. Instead of using a static value for discounts or loyalty points, you can create formulas using mathematical and logical operators combined with metadata values. The final value is calculated dynamically during redemption. The formula builder requires a fallback value. The fallback value is used if the dynamic formula cannot be evaluated due to missing parameters.

Application scope

Dynamic formulas can be used as follows.

Dynamic discount formulas

The dynamic discount formula builder applies to:
  • Order discount
  • Product discount
  • Reward
Used in:
  • Coupon campaigns
  • In-cart promotions
  • Referral codes

Dynamic points formulas

The dynamic points formula builder applies to:
  • Fixed earning rules
  • Proportional earning rules
Used when creating loyalty programs.

Formula builder

Use the Formula builder to define formulas.
1

Open the builder

Click the Formula button next to the discount value or points.
2

Build the formula

Build your formula by selecting an operand followed by an operator.Click + to add elements and X to remove them.
3

Review expression

To review your expression, choose Expression output.You can also edit the formula here or paste a formula prepared earlier.
4

Save

Click Save after defining the formula.
To edit an existing formula, click the Formula button again. To remove a saved formula, click the button next to the Formula button.

Operand reference

Operands represent the values used inside formulas. Example (paste the expression to the Expression output tab and switch to the Formula builder tab to see the result).

Data type

You can use the following data type operands. In some contexts, only number is allowed.
OperandDefinitionExample
NumberValue is a Number.2
TextValue is a String."VIP"

Metadata operands

You can use the following metadata operands.
OperandDefinitionExample
Order metadataOrder metadata attribute of type Number or String.ORDER_METADATA("day_of_week")
Voucher metadataVoucher metadata attribute of type Number or String. Available in dynamic discount formulas only.REDEEMABLE_METADATA("active_on_calendar_month")
Customer metadataCustomer metadata attribute of type Number or String.CUSTOMER_METADATA("customer_life_time_value")
Redemption metadataRedemption metadata attribute of type Number or String. Available in dynamic discount formulas only.REDEMPTION_METADATA("store_list")
Publication metadataPublication metadata attribute of type Number or String. Available in dynamic discount formulas only.PUBLICATION_METADATA("year")
Promotion tier metadataPromotion tier metadata attribute of type Number or String. Available in dynamic discount formulas only (promotion).REDEEMABLE_METADATA("membership_duration")
Depending on the context, the formula builder may accept either metadata with a number type only, or any type (string, boolean, array, and so on).

Order item operands

You can use the following operands in dynamic discount formulas only (product discounts).
OperandDefinitionExample
Order item priceReturns order item price.ORDER_ITEM_PRICE
Order item amountReturns order item amount before stacked discounts.ORDER_ITEM_AMOUNT
Order item subtotalReturns order item subtotal used for stacked discounts.ORDER_ITEM_SUBTOTAL
Order item units quantityReturns order item quantity.ORDER_ITEM_UNITS_QUANTITY
Order item metadataReturns order item metadata.ORDER_ITEM_METADATA("Size")
Order item product metadataReturns product metadata.ORDER_ITEM_PRODUCT_METADATA("category")
(order item price) × 0.01 + 1
If the item price is 6.00, the discount is 1.06.
If the item price is 10.00, the discount is 1.10.

Cheapest order item operands

You can use the following cheapest order item operands.
OperandDefinitionExample
Cheapest order item priceReturns the price of the cheapest line item in the order.CHEAPEST_ORDER_ITEM_PRICE
Cheapest order item amountReturns 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_AMOUNT
Cheapest order item subtotalReturns 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_SUBTOTAL
Cheapest order item units quantityReturns total units of the cheapest order line items.CHEAPEST_ORDER_ITEM_UNITS_QUANTITY
Cheapest order item metadataReturns the cheapest order item metadata of type Number or String.CHEAPEST_ORDER_ITEM_METADATA("Size")
Cheapest order item product metadataReturns the cheapest order item product metadata.CHEAPEST_ORDER_ITEM_PRODUCT_METADATA("category")
The cheapest order item is determined as follows when there are several items with the same price.
  1. 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.
  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.
  3. Finally, it returns the first item from the list of the cheapest items with the lowest subtotal.

Most expensive order item operands

You can use the following most expensive order item operands.
OperandDefinitionExample
Most expensive order item priceReturns the price of the most expensive line item in the order.MOST_EXPENSIVE_ORDER_ITEM_PRICE
Most expensive order item amountReturns 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_AMOUNT
Most expensive order item subtotalReturns 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_SUBTOTAL
Most expensive order item units quantityReturns the total units of the most expensive order line items.MOST_EXPENSIVE_ORDER_ITEM_UNITS_QUANTITY
Most expensive order item metadataReturns the most expensive order item metadata of type Number or String.MOST_EXPENSIVE_ORDER_ITEM_METADATA("Size")
Most expensive order item product metadataReturns the most expensive order item product metadata.MOST_EXPENSIVE_ORDER_ITEM_PRODUCT_METADATA("category")
The most expensive order item is determined as follows when there are several items with the same price.
  1. 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.
  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.
  3. Finally, it returns the first item from the list of the most expensive items with the lowest subtotal.

Order-level operands

You can use the following order-level operands.
OperandDefinitionExample
Order amountReturns order total value.ORDER_AMOUNT
Order items quantityReturns item count.ORDER_ITEMS_QUANTITY
Order units quantityReturns the sum of the units ordered.ORDER_UNITS_QUANTITY

Voucher operands

You can use the following voucher operands. These operands are unavailable for earning rules.
OperandDefinitionExample
Voucher redemption quantityReturns voucher redemption limit.VOUCHER_REDEMPTION_QUANTITY
Voucher redeemed quantityReturns number of redemptions.VOUCHER_REDEEMED_QUANTITY
Voucher publish countReturns the number of times the voucher was published (0 or 1).VOUCHER_PUBLISH_COUNT
Voucher start dateReturns voucher start date.VOUCHER_START_DATE
Voucher expiration dateReturns voucher expiration date.VOUCHER_EXPIRATION_DATE

Promotion tier operands

You can use the following promotion tier operands.
OperandDefinitionExample
Promotion tier start dateReturns promotion tier start date.PROMOTION_TIER_START_DATE
Promotion tier expiration dateReturns promotion tier expiration date.PROMOTION_TIER_EXPIRATION_DATE

Customer operands

You can use the following customer operand. It can be combined only with date operands and operators.
OperandDefinitionExample
Customer birthdateReturns the customer’s birthdate.CUSTOMER_BIRTHDATE

Date operands

You can use the following date operands.
OperandDefinitionExample
Day of monthReturns number of day of month in a date.DAY_OF_MONTH(CUSTOMER_BIRTHDATE)
MonthReturns number of month in a date.MONTH(TODAY)
YearReturns year in a date.YEAR(CUSTOMER_BIRTHDATE)
TodayReturns today’s date.TODAY
NowReturns current date and time.NOW
DateReturns chosen date value.DATE("2023-08-17")
Date timeReturns chosen date and time.DATE_TIME("2023-08-17T14:05:00.000Z")

Expression functions

You can use the following formula operators to create complex expressions.
OperandDefinitionExample
BracketsGroups expression elements together (adds parentheses).(10 - ORDER_METADATA("number_of_store_visits"))
MinLowest value in a range.MIN(PUBLICATION_METADATA("year"); CUSTOMER_METADATA("customer_life_time_value"))
MaxHighest value in a range.MAX(PUBLICATION_METADATA("year"); CUSTOMER_METADATA("customer_life_time_value"))
PowerA number raised to a power.POW(ORDER_METADATA("number_of_store_visits");2)
IfValue based on a logical expression.IF(ORDER_METADATA("number_of_store_visits") > 5;10;3)
Default toReturns the first non-null value of range.DEFAULT_TO(REDEMPTION_METADATA("store_list") / 2;5)
RoundRound a number to a specified number of digits. Positive precision refers to a decimal place indicator. Negative precision indicates an integer place indicator.Assume the customer lifetime value is 75.55.
ROUND(CUSTOMER_METADATA("customer_life_time_value");1)
= 75.60 (precision value equal to 1)
ROUND(CUSTOMER_METADATA("customer_life_time_value");0)
= 76.00 (precision value equal to 0)
ROUND(CUSTOMER_METADATA("customer_life_time_value");-1)
= 80.00 (precision value equal to -1)
FloorRound down to a specified number of digits. Positive precision refers to a decimal place indicator. Negative precision indicates an integer place indicator.Assume the customer lifetime value is 75.55.
FLOOR(CUSTOMER_METADATA("customer_life_time_value");1)

= 75.50 (precision value equal to 1)

FLOOR(CUSTOMER_METADATA("customer_life_time_value");0)

= 75.00 (precision value equal to 0)

FLOOR(CUSTOMER_METADATA("customer_life_time_value");-1)

= 70.00 (precision value equal to -1)
CeilRound up to a specified number of digits. Positive precision refers to a decimal place indicator. Negative precision indicates an integer place indicator.Assume the customer lifetime value is 74.44.
CEIL(CUSTOMER_METADATA("customer_life_time_value");1)

= 74.50 (precision value equal to 1)

CEIL(CUSTOMER_METADATA("customer_life_time_value");0)

= 75.00 (precision value equal to 0)

CEIL(CUSTOMER_METADATA("customer_life_time_value");-1)

= 80.00 (precision value equal to -1)

Operator reference

You can use the following operators depending on the data type.

Number operators

You can use the following operators with the number type.
OperatorDescriptionExample
Add (+)Adds numbers or expressions.A + B
Subtract (-)Subtracts values.A - B
Multiply (x)Multiplies numbers.ORDER_METADATA("day_of_week") x 2
Divide (÷)Divides values.CUSTOMER_METADATA("customer_months_active") ÷ 8
Modulo (%)Returns the remainder after division, meaning it returns the amount “left over” after dividing one number or expression by another.A % B
Greater thanLogical operator returns the Value if true if the value on the left is greater than the value on the right. Otherwise, it returns the Value if false.A > B
Less thanLogical operator returns the Logical operator returns the Value if true if the value on the left is less than the value on the right. Otherwise, it returns the Value if false.A < B
Equal toLogical operator returns the Value if true if the value on the left is equal to the value on the right. Otherwise, it returns the Value if false.A = B
In arrayLogical operator returns the value true if the value on the left is one of the values provided on the right. Otherwise, it returns false.IN_ARRAY
Not in arrayLogical operator returns the value true if the value on the left is NOT one of the values provided on the right. Otherwise, it returns false.NOT_IN_ARRAY

String operators

You can use the following operators with the string type.
OperatorDescriptionExample
IsTrue if strings are equal.is "VIP"
Is notTrue if strings are NOT equal.isNot "Beginner"
ContainsChecks substring presence.contains "California"
Starts withChecks prefix match.startsWith "store_"
Ends withChecks suffix match.endsWith "_sms"
In arrayChecks if value is from a set.IN_ARRAY "EU,EMEA"
Not in arrayChecks if value is NOT from a set.NOT_IN_ARRAY "EU,EMEA"

Date operators

You can use the following operators with the date type.
OperatorDescriptionExample
Days sinceDays between today and a date.DAYS_SINCE(date)
Months sinceMonths between today and a date.MONTHS_SINCE(date)
Years sinceYears between today and a date.YEARS_SINCE(date)
Days untilDays until future date.DAYS_UNTIL(date)
Months untilMonths until future date.MONTHS_UNTIL(date)
Date isDate equality check.DATE_IS
Date is notDate inequality check.DATE_IS_NOT
Is afterDate comparison.IS_AFTER
Is beforeDate comparison.IS_BEFORE

Complex expression operators

Complex expressions combine multiple logical conditions.

AND operator

All conditions must evaluate to true.
Give a customer 20% off when:
  • they have more than 10 store visits
  • AND the purchase occurs on Friday
Otherwise they receive 3% discount.
IF(CUSTOMER_METADATA("number_of_store_visits") > 10 AND ORDER_METADATA("day_of_week") = 5;20;3)

OR operator

At least one condition must evaluate to true.
Example use case:Give a customer 20% off when:
  • they have more than 10 store visits
  • OR the purchase occurs on Friday
Otherwise they receive 3% discount.
IF(CUSTOMER_METADATA("number_of_store_visits") > 10 OR ORDER_METADATA("day_of_week") = 5;20;3)

Nested formulas

Nested formulas allow expressions inside logical conditions. If a condition is true, the logical expression will follow the nested path defined inside the condition. If the condition is false, the logical expression will follow the other path.
IF(ORDER_ITEMS_QUANTITY > 4;IF(ORDER_AMOUNT > 200;25;15);10)
Example logic:
  • more than 4 items AND order > 200 → 25% discount
  • more than 4 items only → 15% discount
  • otherwise → 10% discount

Switch function

Switch expressions allow different values depending on a factor. Example: discount based on store location.
SWITCH(ORDER_METADATA("store_city");SWITCH_CASE("Boston";10) SWITCH_CASE("New York";15);5)
Example:
  • Boston customers get 10% discount
  • New York customers get 15% discount
  • Customers from other locations get 5% discount
Last modified on March 18, 2026