Dynamic Discount Value Builder
The dynamic discount value builder defines how the discount value is calculated.
Contents
- Dynamic Discount Value Builder Overview
- Formula Builder Overview
- Expression Output
- Operand reference
- Cheapest & Most Expensive Order Item
- Operator reference
- Nested Formulas
Dynamic Discount Value Builder
Instead of using a static value for a given discount, you can also create formulas with mathematical and logical operators and assign a dynamic discount value. Discounts will be calculated during redemption based on the provided formula and metadata values.
The formula builder requires a static fallback value in case the dynamic discount value cannot be calculated from the given parameters in the formula.
You can either use the Formula builder utility with step-by-step dialogs that you fill out to build the formula from element building blocks or the Expression output with operators and operands.
The dynamic discount value applies to the following discount types:
- Amount
- Percentage
- Fixed amount
- Unit
and can be used when creating coupon campaigns, in-cart promotions, and referral codes.
Context Specific
The operators and operands in the dynamic discount value 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.
First, select the Plus icon next to the discount value.
Then, begin to build your formula using the formula builder by choosing a type of operand followed by an operator. Use the X icon to delete a number or expression and the + icon to remove the number or expression.
To review your expression, choose Expression output.
Click Save once you have finished defining your dynamic discount formula.
Expression Output
You can view and edit the dynamic discount formula through a mathematical expression using operands and operators. Click Save once you have finished defining your dynamic discount formula.
Operand Reference
You can see the discount values that you can create using different discount operands in the following table.
Operand |
Definition | Example |
Number |
Value is a Number. | 2 |
Text | Value is a String. | Unique string of alpha numeric characters. |
Order metadata |
Value is an order metadata attribute of type Number or String. | |
Voucher metadata |
Value is a voucher metadata attribute of type Number or String. |
![]() |
Customer metadata |
Value is a customer metadata attribute of type Number or String. | ![]() |
Redemption metadata |
Value is a redemption metadata attribute of type Number or String. | ![]() |
Publication metadata |
Value is a publication metadata attribute of type Number or String. | ![]() |
Brackets |
Groups expression elements together; i.e. adds parenthesis to your formula. | ![]() |
Min |
Lowest value in a range | ![]() |
Max |
Highest value in a range | ![]() |
Power |
A number raised to a power; defines the base and exponent. | ![]() |
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. | Assume the customer lifetime value is 75.55. = 75.60 (precision value equal to 1) = 76.00 (precision value equal to 0) = 80.00 (precision value equal to -1) |
Floor |
Round 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. = 75.50 (precision value equal to 1) = 75.00 (precision value equal to 0) = 70.00 (precision value equal to -1) |
Ceil |
Round 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. = 74.50 (precision value equal to 1) = 75.00 (precision value equal to 0) = 80.00 (precision value equal to -1) |
If |
Value based on a logical expression; defines the logical test value, value if expression is true and value if expression is false. | ![]() |
Default |
Returns first non-null value of range. | ![]() |
Order item price | Returns order item price. For each item you can get a particular discount, e.g. (order item price) x 0.01 + 1, if item price is 6.00, the discount is 1.06, if item price is 10.00, the discount is 1.10. | |
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 | Returns order item metadata. | |
Order item product metadata | Returns order item product metadata. | |
Cheapest order item price | Returns the price of the cheapest line item in the order. Read more. | |
Cheapest order item amount | Returns the amount of cheapest line items in the order; for stacked discounts, returns the original amount without any modifications due to other discounts. Read more. | |
Cheapest order item subtotal | Returns the subtotal of cheapest line items in the order; for stacked discounts, each additional discount is based on the result obtained after calculating the previous discount. Read more. | |
Cheapest order item units quantity | Returns total units of cheapest order line items. Read more. | |
Cheapest order item metadata | Returns cheapest order item metadata of type Number or String. Read more. | |
Cheapest order item product metadata | Returns cheapest order item product metadata. Read more. | |
Most expensive order item price | Returns the price of the most expensive line item in the order. Read more. | |
Most expensive order item amount | Returns the amount of most expensive line items in the order; for stacked discounts, returns the original amount without any modifications due to discounts. Read more. | |
Most expensive order item subtotal | Returns the subtotal of most expensive line items in the order; for stacked discounts, each additional discount is based on the result obtained after calculating the previous discount. Read more. | |
Most expensive order item units quantity | Returns total units of most expensive order line items. Read more. | |
Most expensive order item metadata | Returns most expensive order item metadata of type Number or String. Read more. | |
Most expensive order item product metadata | Returns most expensive order item product metadata. Read more. | |
Order amount | Returns order total value, whole cart value. | |
Order items quantity | Returns item count. | |
Order units quantity |
Returns sum of units ordered. | |
Voucher redemption quantity |
Returns voucher's redemption limit. | |
Voucher redeemed quantity |
Returns the number of times the voucher was redeemed. | |
Voucher published count |
Returns the number of times the voucher was published. This value will be either 0 or 1, so this parameter can be used as a security check. For example, if the voucher is assigned (published), then the customer gets a discount, otherwise, no discount. | |
Voucher start date |
Returns the voucher's start date. | |
Voucher expiration date |
Returns the voucher's expiration date. | |
Promotion tier start date |
Returns the promotion tier's start date. | |
Promotion tier expiration date |
Returns the promotion tier's expiration date. | |
Customer's birthdate |
Returns the customer's birthdate. | |
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 | Most Expensive Order Item |
---|---|
This is how the cheapest order item is defined. |
This is how the most expensive order item is defined. |
|
|
Operator reference
Number Operators
Here are the discount formula operators you can choose from for properties of Number type.
Operand |
How does it work? |
Use case |
Add + |
Adds numbers or expressions. | Example with missing metadata property defaulting to fallback value Missing metadata property: number_of_store_visits |
Subtract - |
Subtracts numbers or expressions. | Give customer a percent off for every year since they first became a customer. year: 2022
Calculated dynamic discount value: 10%
Fallback value: 10% |
Multiply x |
Multiplies numbers or expressions. | Give customer a discount proportional to the day of the week; assuming i.e. days of the week are defined as: Sunday - day_of_week: 5
Calculated dynamic discount value: $10
Fallback value: $10 |
Divide ÷ |
Divides numbers or expressions. | Give customer an eighth for every month the customer was active. customer_months_active: 8
Calculated dynamic discount value: $10
Fallback value: $10 |
Modulo % |
Returns remainder after division, i.e. returns the amount "left over" after dividing one number or expression by another. | Give customer a certain number of free items based on a custom formula. active_on_calendar_month: 10
Calculated dynamic discount value: 1 Free item
Fallback value: 1 Free item |
Greater than > |
Logical operator returns the Value if true if the value on the left is greater than the value on the right, otherwise returns the Value if false. | Give customer 20% off every time they make a purchase after their 10 th store visit; otherwise the customer receives a standard 3% discount. IF(CUSTOMER_METADATA("number_of_store_visits") > 10;20;3) |
Less than < |
Logical operator returns the Value if true if the value on the left is less than the value on the right, otherwise returns the Value if false. | Give customer 3% off each store visit until their 9 th store visit; then beginning from their 10th store visit, give the customer a 20% discount. IF(CUSTOMER_METADATA("number_of_store_visits") < 10;3;20) |
Equal to = |
Logical operator returns the value if true if the value on the left is equal to the value on the right, otherwise returns the Value if false. | Give customer 50% off on their 50 th store visit. IF(CUSTOMER_METADATA("number_of_store_visits") = 50;50;0) |
String Operators
Here are the discount formula operators you can choose from for properties of String type.
Operand |
How does it work? |
Use case |
Is | Logical operator returns true if the strings are equal and false otherwise. | Give customer $20 off every time they make a purchase by following a link from Facebook; otherwise the customer receives a discount equal to their age. IF(CUSTOMER_METADATA("acquisition_channel") is "Facebook";20;CUSTOMER_METADATA("age")) |
Is not | Logical operator returns true if values are NOT equal and false otherwise. | Give customer 10% off every time they make a purchase except when they are acquired through Twitter; otherwise the customer receives a 3% discount. IF(CUSTOMER_METADATA("acquisition_channel") isNot "Twitter";10;3) |
Contains | Logical operator returns true if the value on the left contains the value on the right. | Give customers living in California 3 free coffees. IF(CUSTOMER_METADATA("location") contains "California";3;0) |
Starts with | Logical operator returns true if the value on the left starts with the value on the right. | Give customer buying at one of our stores on the Jersey shoreline a 15% discount. (IF(REDEMPTION_METADATA("location_id") startsWith "Jersey_Shoreline_store_";15;0)) |
Ends with | Logical operator returns true if the value on the left ends with the value on the right. | Give customer 50% off if they receive a code via SMS; otherwise they will receive a 35% discount. IF(PUBLICATION_METADATA("publication_method") endsWith "_sms";50;35) |
Date Operators
Here are the discount formula operators you can choose from for properties of Date type.
Operand |
How does it work? |
Use case |
Days since | Returns number of days from the start date (variable) to the end date (current date), but not including the end date. YYYY-MM- DDCurrent
# days excluding end date
|
Incentivise customers to make another purchase after they make an order by creating a discount that depreciates with the number of days since they last made a purchase. IF(DAYS_SINCE(CUSTOMER_METADATA ("date_last_purchase")) < 31;30 / DAYS_SINCE(CUSTOMER_METADATA ("date_last_purchase"));0) |
Months since | Returns number of months from the start date (variable) to the end date (current date) excluding the end date. YYYY- MM-DDCurrent
# months excluding end date
|
If you are subscribed for more than 12 months, you'll get a discount of 20%. Otherwise, you'll get 10%. IF(MONTHS_SINCE(CUSTOMER_METADATA ("date_subscribed")) > 12;20;10) |
Years since | Returns number of years from the start date (variable) to the end date (current date) excluding the end date. YYYY-MM-DDCurrent
# years excluding end date
|
Give customers an increasing discount based on the number of years they are a customer. YEARS_SINCE(CUSTOMER_METADATA ("acquisition_date")) Get a discount equal to your age! YEARS_SINCE(CUSTOMER_BIRTHDATE) |
Days until | Returns number of days from the start date (current date) to the end date (variable) excluding the end date. YYYY-MM- DDVariable
# days excluding end date
|
Early bird scenario - If you want customers to buy the items sooner, you can influence the discount based on the number of days from/to a specific date. A decreasing percentage discount that goes to zero at the voucher expiration date. For each day until the expiration date, the customer will get 2 percent off. |
Months until | Returns number of months from the start date (current date) to the end date (variable) excluding the end date. YYYY- MM-DDVariable
# months excluding end date
|
Buy six months or more prior to new year's eve and pay 15% less! Otherwise you'll get 5% off. Here, the expiration date would be set to new year's eve. IF(MONTHS_UNTIL(VOUCHER_EXPIRATION_DATE) > 6;15;5) |
Day of month | Returns number of day of month in a date. YYYY-MM- DDVariable |
Customer's whose birthday falls on the 6th of the month get a 10% off their purchase. All other customers get a 5% off. IF(DAY_OF_MONTH(CUSTOMER_BIRTHDATE) = 6;10;5) |
Month | Returns number of month in a date. YYYY- MM-DDVariable |
Incentivize customers to make orders through the year. Customer's receive higher amount discounts applied to their order with each consecutive month. The value of the current month is multiplied by a factor of 2. MONTH(TODAY) * 2 |
Year | Returns year in a date. YYYY-MM-DDVariable |
Incentivize younger folks to make purchases by giving higher amount discounts for younger customers. YEAR(CUSTOMER_BIRTHDATE) / 100 |
Today | Returns today's date. You need to combine this operator with another one, such as Day of month, month or year to extract data from Today. YYYY-MM-DD Variable |
Give a percentage discount based on the day of the month, i.e. the percent discount will be 11% off on the 11th day of the month. DAY_OF_MONTH(TODAY) |
Now | Returns current date and time, i.e. 2023-03-06T09:04:32.694Z. You need to combine this operator with another one, such as Day of mont, month or year to extract data from Now. YYYY-MM-DDThh:mm:ss.sss Variable |
Take an amount off the order equal to the current month. For March, take $3 off, for December take $12 off the order. MONTH(NOW) |
Complex Expression Operators
Here are the discount formula operators you can choose from for creating complex expressions.
Operand |
How does it work? |
Use case |
And | Two or more relations can be logically joined using the logical operator AND . Both relations must be true for the complex expression to be true. |
Give customer 20% off every time they make a purchase after their 10 th store visit AND the customer makes a purchase on a Friday; otherwise the customer receives a standard 3% discount. IF(CUSTOMER_METADATA("number_of_store_visits") > 10 AND ORDER_METADATA("day_of_week") = 5;20;3) |
Or | Two or more relations can be logically joined using the logical operator OR . If either relation is true, the complex expression is true. |
Give customer 20% off every time they make a purchase after their 10 th store visit OR the customer makes a purchase on a Friday; otherwise the customer receives a standard 3% discount. IF(CUSTOMER_METADATA("number_of_store_visits") > 10 OR ORDER_METADATA("day_of_week") = 5;20;3) |
Nested Formulas
You can create nested expressions by embedding statements within true and false blocks of logical IF statements.
How does it work? |
Use case |
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. |
Give customer 25% off if the order amount is greater than 200 and the quantity of items in the cart is more than 4; otherwise give customers 15% off. If the customer does not have more than 4 items in the cart, the customer gets 10% off. IF(ORDER_ITEMS_QUANTITY > 4;IF(ORDER_AMOUNT > 200;25;15);10) |