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
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 stepbystep 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, incart promotions, and referral codes.
Formula Builder
You can use the Formula builder utility with stepbystep 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.  
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 nonnull 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. 

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. 

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. 

Order amount  Returns order total value, whole cart value. 

Order items quantity  Returns item count. 

Order units quantity 
Returns sum of units ordered. 

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 10^{th} 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) 
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) 