You are here:
Example: Create an Expression Set to Calculate Discounted Membership Fees
Configure the expression set version to calculate a contact’s age from their birth date, look up the contact’s step count to get the steps-based discount, and return the discounted gym membership fee after subtracting the total discount from the base membership fee.
Required Editions
| User Permissions Needed | |
|---|---|
| To create a field alias for the Birthdate field in the Contact object: | System Administrator for a Salesforce org with Business Rules Engine |
| To create the expression set, and design and activate its version | Rule Engine Designer |
The field alias (Applicant.Birthdate) for using the value of the Birthdate field from the Contact object must be created in Setup, and available to use in the expression set. See Create Source Field Aliases.
Create an expression set named AnnualGymMembership. In Version 1 of this expression set, add steps to use the contact’s inputs and return the discounted gym membership fees.
- From the app navigation menu of Business Rules Engine, select Expression Sets.
- Click New.
-
Enter AnnualGymMembership as the name, and save your work.
The expression set and its first version are created.
- On the record page for the new expression set, on the Versions tab, select AnnualGymMembership V1, and then click Open in Expression Set Builder.
-
Set the properties for the expression set version:
-
Click
, and enter a start date time for the
expression set version.
-
Enter a rank.
The default is 1.
- Select Show decision explanation.
- Close the Expression Set Properties panel.
-
Click
-
Create resources for the expression set:
-
Click
.
-
Click Add Resource, and then create these variables and constants.
Note After adding a resource, to add the next resource, click Done and New. After adding all required resources, click Done.Resources Resource Type Variable NAME Data Type Decimal Default Value Constant GymFees Currency 0 1000 Variable ContactAge Number 0 — Variable TotalDiscount Percent 0 — Variable DiscountedGymFees Currency 2 —
Tip Save the version after making any change. -
Click
-
To get the discount percent based on the step count, add a Lookup Table step.
-
Click
on the builder canvas, and select
Lookup Table.
-
Search for and select StepsBasedDiscount.
The matrix is added and the input and output columns from the matrix appear as local variables in the resources list.
-
Click
-
To calculate the contact’s age from their birth date, add a Calculation step.
-
Click
on the builder canvas, and select
Calculation.
- In the Formula field, search for and select AGE (Date).
-
To replace Date in Age (Date) with the value of the Birthdate field on the Contact
object, search for and select Applicant.Birthdate so that the formula
looks like this: Age(Applicant.Birthdate).
Here. Applicant is the object alias for Contact, and Birthdate is the field alias for the Birthdate field in Contact.
- In the Output Variable field, search for and select ContactAge.
-
Click
-
To use the contact’s age to a get the applicable age-based discount, add a Lookup
Table
step.
-
Click
on the builder canvas, and select
Lookup Table.
-
Search for and select AgeBasedDiscount.
The matrix is added and the input and output columns from the matrix appear as local variables in the resources list.
-
Click
-
To calculate the total discount based on the contact’s age and step count, add a
Calculation step.
-
Click
on the builder canvas, and select
Calculation.
-
In the Formula field, enter this formula:
StepBasedDiscount_Discount + AgeBasedDiscount_Discount. - In the Output Variable field, search for and select TotalDiscount.
-
Click
-
To calculate the discounted gym membership fees, add a Calculation step.
-
Click
on the builder canvas, and select
Calculation.
-
In the Formula field, enter this formula:
GymFees - ( TotalDiscount * GymFees ). - In the Output Variable field, search for and select DiscountedGymFees.
-
Click
-
Select each step individually, click
, and select Include in output.
Tip To save the version, this action is required for at least one step. However, to include step-wise details in the Decision Explainer logs, complete this action for every step. - Click Simulate and test the version by entering sample inputs.
- Activate the version.
Did this article solve your issue?
Let us know so we can improve!

