Calculation Rules
Overview
Calculation Rules (commonly referred to as "Earn Rules") specify how Members earn Metrics (such as reward points) for different Activity types. Calculation Rules are typically used by clients who have an "earn and burn" style program, in which Members makes purchases in order to earn points. Members can then spend those points on Rewards, or to make other purchases.
A Calculation Rule comprises the following elements:
-
Activity Type: An action that a Member must take, such as a purchase.
-
Metric: The Metric whose value is calculated by this Calculation Rule.
-
Condition: If a condition is specified, the Calculation Rule is applied only if the condition is true.
-
Calculation: The earned Metric value from this Rule; note that this value may combine with the result of other Calculation Rules for determining the final result.
-
Status: The life cycle status of the Calculation Rule, including its effectivity period.
Calculations and Conditions can be written as Groovy expressions. You can use Calculation Functions to encapsulate common scenarios and to simplify the process of authoring Calculation Rules. Further, custom encapsulation of Calculation or Condition scenarios can be written as Member Functions. Many rule calculations may be accomplished as a lookup from a spreadsheet of key/value pairs.
Rule Groups
The platform allows you to assign Calculation Rules to a Rule Group. Rule Groups serve as an organizational function, and also as tool to implement common loyalty scenarios. Rule Groups are defined within the Cheetah Loyalty application. For more details on setting up Rule Groups, please see the Loyalty Online Help.
Examples
Below are several examples of common Calculation Rules.
Description: For every point-of-sale Purchase, earn 1 Reward Point for each $1 spent.
getActivityValue('amount')
Description: Give a 15 Reward Point bonus for purchases more than $200.
getActivityValue('amount') >= 200
Description: Give different Reward Points for items purchased. The Lookup table "point_lookup" defines how many points to give for every dollar spent for items in different categories. The result in the lookup is stored in the column "point_factor." The value in "point_factor" in the Lookup table needs to be multiplied by the amount spent on the item.
sumActivityItems({item -> getLookupValue ('point_lookup', item.category, 'point_factor') * item.amount})
Access
To access the Calculation Rules screen, select Definitions from the Main Navigation Menu, then select Metrics > Calculation Rules from the Sub-Category menu.
Features
The Calculation Rules screen provides the following features:
Click hereClick here
Search
The search feature allows you to search for
a specified text string anywhere within the Calculation Rule's Display
Name or Internal Name.
-
Optionally, in the
search field near the top of Calculation Rules screen, enter
the desired text string.
-
Optionally, from the
"Status" drop-down menu, select an Calculation Rule
status (or "Any status").
-
Optionally, from the
"Group" drop-down menu, select an Calculation Rule
Group (or "Any Group").
-
Optionally, from the
"Activity Type" drop-down menu, select one or
more Activity Types on which the Calculation Rule is based (or
"Any Activity Type").
-
Optionally, from the
"Effectivity" drop-down menu, select an Calculation
Rule effectivity (or "Any effectivity").
-
Press Enter, or click
the search button (magnifying glass icon).
-
The Calculation Rules screen
is refreshed to show only the Calculation Rules that meet your
search criteria. Please note that if you enter multiple
search criteria, the platform displays only the Calculation Rules
that meet ALL criteria.
-
To remove all search
criteria, click the remove button ("X" icon).
Expand / Collapse
All Calculation Rules are displayed beneath a sub-heading that indicates the Calculation Rule Group. Optionally, you can expand / collapse a Calculation
Rule Group by clicking the minus-sign or plus-sign icon next
to the Calculation Rule name.
|
Click hereClick here
To create a new Calculation Rule:
-
In the "Enter Display Name" field, enter the Display Name value for the new Calculation Rule.
-
Click create to display the "Edit Calculation Rule" pop-up window.
-
The "Display Name" field is populated with the value you entered above; optionally edit this value.
-
The "Internal Name" is automatically populated based on the Display Name value. This field is disabled by default. To edit the Internal Name, check edit internal name. A confirmation dialog box is displayed; click ok. Edit the Internal Name value.
-
In the "Description" field, enter a description of the Calculation Rule.
-
From the "Rule Grouping" drop-down menu, select the Calculation Rule Group to which this new Rule should be assigned.
-
Click into the "Activity Type" field, and select an Activity Type from the drop-down menu. Repeat this step as needed to assign additional Activity Types to this Calculation Rule.
-
From the "Metric" drop-down menu, select the Metric that this Calculation Rule will calculate.
-
Click save.
Define the Condition
When the Member performs the Activity specified for a Calculation Rule, the platform checks the Condition, which is represented as a logical expression. The Calculation Rule is invoked only if this Condition is satisfied.
Note: The use of Conditions is optional. If the Condition is not defined, the Calculation Rule will apply to every individual who performs the assigned Activity Type.
To define the Calculation Rule Condition
-
Find the desired Calculation Rule on the Calculation Rules screen.
-
Click the Edit icon within the Condition column to display the Conditions pop-up window.
-
Click the Add button (plus-sign icon) and select "Add Rule."
-
From the first drop-down menu, select the desired field.
-
Select a mathematical operator.
-
Enter or select a value.
-
Repeat the above steps as needed to define more Rules.
-
Once you define more than one Rule, select the logical operator. From the "Include customers that meet" drop-down menu above the list of Rules, select either:
-
All of the following (i.e., an AND operator)
-
Some of the following (i.e., an OR operator)
-
Optionally, to clear all Rules from this Condition, click remove condition.
-
If you need to define additional Conditions for this Calculation Rule, click add condition. Repeat the above steps to define the Rule, or Rules, for the Condition.
Note: Instead of defining a Rule through the user interface, you can provide code to perform more complex query logic. Enter your custom code in the Advanced Expression field.
-
Click save.
When defining the Rules for the Condition, you can optionally organize the Rules into a Group to create more sophisticated logical statements.
-
Within the Conditions pop-up window, click the Add button (plus-sign icon) and select "Add Rule Group."
-
Follow the steps described above to define the Rule, or Rules, within the Group, as well as the Group's logical operator.
-
If you need to delete a Group (and all Rules within it), click the Delete icon within the Group.
-
Click save.
Define the Calculation
The Calculation specifies the mathematical formula for the Metric. If the Condition is met, the platform calculates the appropriate adjustment to the Member's Metric value.
Note: Defining the Calculation requires knowledge of the Groovy programming language.
-
Find the desired Calculation Rule on the Calculation Rules screen.
-
Click the Edit icon within the Calculation column to display the "Calculation Rule" pop-up window.
-
Next to Authoring Mode, select "Expression."
Note: This Help topic doesn't cover the Template authoring mode.
-
In the Expression field, enter the Groovy expression.
-
Optionally, click validate expression to validate the Groovy code. A message is displayed, indicating the results of the validation.
-
Click save.
|
Click hereClick here
To edit the status and Effectivity Period for a Calculation Rule:
-
Find the desired Calculation Rule on the Calculation Rules screen.
-
Click the Edit icon within the Status column to display the Calculation Rule pop-up window.
-
From the "Status" drop-down menu, select the Calculation Rule status.
-
Make any necessary changes to the Calculation Rule's overall effectivity. Valid values are:
-
Always: This Calculation Rule doesn't expire.
-
Schedule: Enter a start date and end date. Optionally, check "Recurring" to use a recurring schedule. Select the desired schedule from the "Recurring Schedule" drop-down menu, or define a new recurring schedule (see below for details on that process).
-
Click save.
To define a new recurring schedule for an item's effectivity:
-
From the "Recurring Schedule" drop-down menu, select "Enter Schedule." The "Repeat" pop-up window is displayed.
-
From the "Frequency" drop-down menu, select a recurrence frequency -- Weekly or Monthly.
-
In the text field, enter the interval.
-
For a Weekly frequency, select one or more days of the week. For example, "Tuesdays and Thursdays."
-
For a Monthly frequency, choose one of the following options:
-
Day of month: Select one or more days of the month. For example, "the 15th and the 30th."
-
Day of week: Select one or more days of the week, for each of the four weeks within a month. For example: "the second Wednesday of the month."
-
Click ok. The system adds the new schedule to the "Recurring Schedule" drop-down menu.
|
Click hereClick here
After you've created a Calculation Rule, you must
deploy the Calculation Rule metadata. When you deploy the Calculation Rules
metadata to the server, the process automatically deploys
the metadata for ALL modified Calculation Rules.
-
From the "Actions"
menu in the top-right corner, select "Validate Earn
Rules Metadata."
Note: You can deploy metadata immediately,
but the best practice is to validate the Calculation Rules logic
before deploying metadata to ensure no incorrect expression
code gets deployed to the server that could cause issues.
-
If the validation step
passes, you'll see a message that says, "Earn Rules
metadata is valid." If the validation step fails,
you'll receive an error message; review and correct your
Earn Rules expressions, then retry the validation step.
-
Click deploy
earn rules metadata.
-
If the deployment was
successful, you'll see a message that says, "Earn
Rules metadata as been deployed."
|
Click hereClick here
To see the details of what Calculation Rules metadata
has been deployed:
-
From the "Actions"
menu in the top-right corner of the screen, select "View
Deployed Earn Rules." The "View Snapshot"
pop-up window is displayed.
-
Click the plus-sign
to expand the message to view additional details, such
as the total number of deployed Calculation Rules. You can also
drill in deeper, to see details of each deployed Calculation
Rules (Calculation Rule name, type, conditions, etc.).
-
When finished, click
the "X" icon to close the pop-up window.
|
Click hereClick here
The sequence in which the Calculation Rules appear
within a Calculation Rule Group controls the sequence in which the
platform executes the Calculation Rules in that Group. For example,
if you have five Calculation Rules within a Group, and that Group
is configured to use the "Execute only first applicable
rule" strategy, the platform will interrogate the first
Calculation Rule in the Group. If that condition fails, the platform
will move on to the second Calculation Rule, and so forth.
To rearrange the Calculation Rules:
-
To the left of the
desired Calculation Rule, click and hold on the "handle"
area.
-
Drag-and-drop the Calculation
Rule to its desired new sequence.
Note: You can't drag-and-drop an Calculation Rule
into a different Rule Group. To change a Calculation Rule's
inclusion in a Group, you must edit its properties (see below
for more details on this process).
|
Click hereClick here
To edit the properties of a Calculation Rule:
-
Find the desired Calculation Rule on the Calculation Rules screen.
-
Within the appropriate column ("Calculation Rule," "Condition," "Calculation," or "Status" ) of the desired Calculation Rule, click the edit icon. The corresponding pop-up window is displayed.
-
Make any necessary changes to the Calculation Rule properties.
-
Click save.
|
Click hereClick here
To delete a Calculation Rule:
-
Find the desired Calculation
Rule on the Calculation Rules screen.
-
Within the right-most
column of the desired Calculation Rule, click the Delete icon.
A confirmation dialog box is displayed.
-
Click confirm.
|
Click hereClick here
The platform allows you to copy a Calculation Rule to use as the basis for a new Calculation Rule. To copy
a Calculation Rule:
-
Find the desired Calculation
Rule on the Calculation Rules screen.
-
Within the right-most
column of the desired Calculation Rule, click the Copy icon.
The system creates a new Calculation Rule. The default name of
the new Calculation Rule is the name of the original Calculation Rule,
followed by a counter, such as "(1)."
|
Click hereClick here
To download the underlying JSON code for all Calculation Rules:
-
From the "Actions" menu in the top-right corner of the screen, select either "Download JSON" or "Download JSON (Batch)."
-
The JSON code for all Calculation Rules in your account is displayed in a separate browser tab.
|
Back to Metrics Overview
Last Updated: April 2022