You are here:
Accumulated Variables in Salesforce Spiff
An accumulated variable is like a running total, where Salesforce Spiff sums a field or value within a sorted data filter and returns a cumulative value up to a current record. An accumulated variable helps you quickly sum multiple values with fewer calculations.
Required Editions
| Available in: both Salesforce Classic (not available in all orgs) and Lightning Experience |
| Available in: Enterprise, Unlimited, and Developer Editions |
| Available for an additional cost in: Professional Edition with Web Services API Enabled |
For example, consider a data filter that returns five deals.
| Deal | Amount |
|---|---|
| Deal 1 | $500 |
| Deal 2 | $1,800 |
| Deal 3 | $750 |
| Deal 4 | $865 |
| Deal 5 | $1,350 |
If you're maintaining a running total of these amounts, each successive deal represents a different calculation. For a manual sum, each new deal increases the number of values to include in the sum calculation. With an accumulated variable, each new deal is a calculation of only the previous total plus the new value.
| Deal | Amount | Running Total with Manual Sum | Running Total with Accumulated Variable |
|---|---|---|---|
| Deal 1 | $500 | $500 | $500 |
| Deal 2 | $1,800 | $500 + $1,800 = $2,300 | $500 + $1,800 = $2,300 |
| Deal 3 | $750 | $500 + $1,800 + $750 = $3,050 | $2,300 + $750 = $3,050 |
| Deal 4 | $865 | $500 + $1,800 + $750 + $865= $3,915 | $3,050 + $865 = $3,915 |
| Deal 5 | $1,350 | $500 + $1,800 + $750 + $865 + $1,350= $5,265 | $3,915 + $1,350 = $5,265 |
For best performance, use the fewest calculations. Calculated fields compute one time for every record, and summary calculations compute one time for every statement. Consider how the calculation time scales over thousands of records. If you have 10,000 deals, the manual sum requires 50,005,000 calculations, but the accumulated variable requires only 19,999 calculations.
Keep these considerations in mind when working with accumulated variables.
- Pair an accumulated variable with the
mpercent()andmamount()functions, which require an initial value. For example, if you're accumulating ARR, you can create a calculated field such as Prior_YTD_ARR that subtracts the current deal's ARR from the accumulated total. - A common error with accumulated variables occurs when a record in the rule's data filter is missing from the accumulated variable's data filter. To identify and troubleshoot errors, create test data filters that include all the components needed for accumulation. Pair these test data filters so you can identify which subfilters are excluding the missing records.
- An accumulated variable can’t sort null values. For example, if some deals don't have a close date and you want to group them together at the start or end of sorted results, you must create a calculated field. To make sure that deals are sorted last, use a future date. You can also manipulate the sorting order with calculated fields.
- To improve performance, turn off trace.
- Turn on an Accumulated Variable in Salesforce Spiff
Analyze sales data and identify trends and patterns with accumulated variables. - Examples of Manual Accumulated Variables with the Let Function
Sometimes, an accumulated variable in Salesforce Spiff can't calculate an amount, so you must manually create accumulated variables by using thelet()function.

