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
- The Cheapest & Most Expensive Order Item
- Operator Reference
- Nested Formulas
- Switch Function
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 formula's given parameters.
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, click the Formula button 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. Click the X button to delete a number or expression and the + button to add a number or expression.
To remove an operator you have entered, click on it and click the Remove button.
To review your expression, choose Expression output.
Click Save once you have finished defining your dynamic discount formula.
To edit your existing formula, click the Formula button next to the discount value.
To remove a saved formula, click — button next to the Formula button.
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 alphanumeric 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 parentheses 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 to |
Returns the 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) × 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. |
|
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 the 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 the 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 the cheapest order line items. Read more. |
|
Cheapest order item metadata | Returns the cheapest order item metadata of type Number or String. Read more. |
|
Cheapest order item product metadata | Returns the 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 the 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 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. Read more. |
|
Most expensive order item units quantity | Returns the total units of the most expensive order line items. Read more. |
|
Most expensive order item metadata | Returns the most expensive order item metadata of type Number or String. Read more. |
|
Most expensive order item product metadata | Returns the most expensive order item product metadata. Read more. |
|
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. |
|
Voucher redemption quantity |
Returns the voucher's redemption limit. |
|
Voucher redeemed quantity |
Returns the number of times the voucher was redeemed. |
|
Voucher published count |
Returns the number of the 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 birthdate |
Returns the customer's birthdate. |
|
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 Current |
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) |
Date | Returns the chosen date, for example 2023-08-17. YYYY-MM-DD Variable |
Incentivize customers to buy an item on its release date (2023-08-17) to have a $10 discount. Otherwise, they receive a $5 discount. IF(DATE("2023-08-17");10;5) |
Date time | Returns the chosen date and time, for example 2023-08-17T14:05:00.000Z. YYYY-MM-DDThh:mm:ss.sss Variable |
Incentivize customers to buy an item within 5 days since its release date and time to have a $10 discount. Otherwise, they will receive a $5 discount. IF(DAYS_SINCE(DATE_TIME("2023-08-17T14:05:00.000Z")) < 5;10;5) |
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 | Most Expensive Order Item |
---|---|
This is how the cheapest order item is determined. |
This is how the most expensive order item is determined. |
|
|
Operator reference
Number Operators
Here are the discount formula operators you can choose from for properties of Number type.
Operator |
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 a 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 a customer a discount proportional to the day of the week if the week are defined as: Sunday - day_of_week: 5
Calculated dynamic discount value: $10
Fallback value: $10 |
Divide ÷ |
Divides numbers or expressions. | Give a customer an eighth for every month the customer was active. customer_months_active: 8
Calculated dynamic discount value: $10
Fallback value: $10 |
Modulo % |
Returns the remainder after division, i.e. returns the amount "left over" after dividing one number or expression by another. | Give a 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, it returns the Value if false. | Give a 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, it returns the Value if false. | Give a 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, it returns the Value if false. | Give a customer 50% off on their 50 th store visit. IF(CUSTOMER_METADATA("number_of_store_visits") = 50;50;0) |
In array | Logical operator returns the value true if the value on the left is one of the values provided on the right. Otherwise, it returns false. |
Give a customer a $10 discount if the number of units in an order is 3, 6, 9, 12, or 15. Otherwise, they get a 5$ discount. IF(ORDER_UNITS_QUANTITY IN_ARRAY "3, 6, 9, 12, 15";10;5) |
Not in array | Logical 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. |
Give a customer a $10 discount if the number of units in an order is NOT 1, 2, 3, or 4. Otherwise, they get a $10 discount. IF(ORDER_UNITS_QUANTITY NOT_IN_ARRAY "1, 2, 3, 4";10;5) |
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. Otherwise, it returns false. | Give a 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. Otherwise, it returns false. | Give a 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. Otherwise, it returns false. | 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. Otherwise, it returns false. | Give a 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. Otherwise, it returns false. | Give a 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) |
In array | Logical operator returns the value true if the value on the left is one of the values provided in the text string, separated by a comma. Otherwise, it returns false. | Give a customer $10 off if the order is placed inside a given region. Otherwise, they receive a $5 discount. IF(ORDER_METADATA("region") IN_ARRAY "EU, EMEA";10;5) |
Not in array | Logical operator returns the value true if the value on the left is NOT one of the values provided in the text string, separated by a comma. Otherwise, it returns false. | Give a customer $10 off if the order is placed outside a given region. Otherwise, they receive a $5 discount. IF(ORDER_METADATA("region") NOT_IN_ARRAY "EU, EMEA";10;5) |
Date Operators
Here are the discount formula operators you can choose from for properties of Date type.
Operator |
How does it work? |
Use case |
Days since | Returns the number of days from the start date (variable) to the end date (current date), excluding the end date. YYYY-MM- DDCurrent
# days excluding end date
|
Incentivize 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 the 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 a customer has been subscribed for more than 12 months, they will get a discount of 20%. Otherwise, they will 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 the 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 the 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
|
Customers can buy six months or more prior to new year's eve and pay 15% less!. Otherwise, they will get 5% off. Here, the expiration date would be set to new year's eve. IF(MONTHS_UNTIL(VOUCHER_EXPIRATION_DATE) > 6;15;5) |
is |
Returns true if the date on the left is the same as the date on the right. Otherwise, it returns false. |
Give a customer a $10 discount if today is a specific day. Otherwise, they get a $5 discount. IF(TODAY DATE_IS DATE("2023-08-22");10;5) |
Is not | Returns true if the date on the left is NOT the same as the date on the right. Otherwise, it returns false. |
Give a customer a $10 discount if today is NOT a specific day. Otherwise, they get a $5 discount. IF(TODAY DATE_IS_NOT DATE("2023-08-22");10;5) |
Is after | Returns true if the date on the left is after the date on the right. Otherwise, it returns false. | Give a customer a $10 discount if today is after a specific date. Otherwise, i.e. before the defined date, they get a $5 discount. IF(TODAY IS_AFTER DATE("2023-08-22");10;5) |
Is before | Returns true if the date on the left is before the date on the right. Otherwise, it returns false. | Give a customer a $10 discount if they place an order before a specific date. Otherwise, i.e. after the defined date, they get a $5 discount. IF(NOW IS_BEFORE DAY_OF_MONTH(DATE("2023-08-22"));10;5) |
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 components can be logically joined using the logical operator AND . Note: All components must be true for the complex expression to be true. |
Give a 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 components can be logically joined using the logical operator OR .Note: If at least one component is true, the complex expression is true. |
Give a 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 a 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 the customer 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) |
Switch Function
You can create expressions using the switch function to create different discount rates based on a given factor. For example, give a different discount rate based on where the order is placed.
How does it work? |
Use case |
Switch the discount value based on a predefined factor. |
Give a customer 10% off if the order is made in a Boston store, 15% if the order transaction occurs in a New York store. Otherwise, give the customer a 5% discount. SWITCH(ORDER_METADATA("store_city");SWITCH_CASE("Boston";10) SWITCH_CASE("New York";15);5) |