Summary Variable:
- In Salesforce CPQ (Configure, Price, Quote), a summary variable is a special type of variable that allows you to perform calculations and aggregate data based on the line items in a quote. It helps you derive useful information or metrics from the quote, such as total quantities, total prices, or any other custom calculations.
- Summary variables are defined and used within quote line editor formulas. They allow you to access and manipulate data across multiple quote line items simultaneously.
- You define a summary variable by specifying its name, data type, and any initial value or formula. The formula determines how the variable is calculated or aggregated based on the line items in the quote.
For example, you could define a summary variable called "Total Quantity" with an initial value of 0, and a formula that adds up the quantity field of each quote line item. - Summary variables can have different scopes, which determine where they are accessible and applicable. The available scopes are:
- Quote: The summary variable applies to the entire quote, aggregating data from all quote line items.
- Group: The summary variable applies to specific groups of quote line items. You can define groups based on criteria such as product category, bundle, or custom fields.
- Product: The summary variable applies to individual quote line items, allowing you to perform calculations or aggregations at the line item level.
- Once you've defined a summary variable, you can use it in formulas within the quote line editor. For example, you can reference the "Total Quantity" summary variable in a formula to calculate the average price per unit or to trigger certain actions based on a threshold quantity.
Use Case: For any Trail product (opportunity type is trail) the max quantity should not exceed 4.
Pre-Requisite: Please check the Alert and Validation Rule article to understand the steps fully.
Steps to Configure Summary Variable:
- Go to the Product Rules Click on New. Give the following values -
Product Rule Name: Free Channel Trail
Type: Validation
Scope: Quote
Conditions Met: All
Evaluation Event: Save
Message: Max 4 Trail products can be added in on Quote.
Active: True
Save the record. - Now as per the Use case, we need to fire this product rule only if it is a Trail Quote. To do that we need to add an Error Condition with the following values-
Rule - Free Channel Trail
Index: 20
Tested Object: Quote
Tested Field: OpportunityType__c
Operator: equals
Filter Type: Value
Filter Value: Trail
Save Changes - Now we need to add another Error Condition. In that condition, we need to check the count of line items. Let's look into the steps -
- Index: 10
- Tested Variable: Click on the New Summary Variable button. Now let's create the summary variable record -
Variable Name: Total Quantity
Aggregate Function: Count
Target Object: Quote Line
Aggregate Field: Quantity
Save the Record - Now fill in Filter Information-
Operator: Greater than
Filter Type: Value
Filter Value: 4
Save the record. - Go to Opportunity and create a new opportunity with Type - Trail. If you don't see Trail in the picklist please add that value.
- Create a quote under that opportunity
- Click on the Edit Lines button and add any product. For example - 500 + Channel
- Now increase the quantity and give values more than 4 and click on save. You will notice System will throw the error.