---
schema_version: "1"
id: e1a59c34fb1ea52ef8caf87e65ea37c060ed20457cea6b40fb28e072cf99342f
title: The Looping Feature in Calculation Procedures (Managed Package)
collection: admin
version: current
locale: en-us
portal_url: https://docs.salesforce.com/admin/current/en-us/xcloud/264-0-0/os_the_looping_feature_in_calculation_procedures.md
canonical_url: https://help.salesforce.com/s/articleView?id=xcloud.os_the_looping_feature_in_calculation_procedures.htm&release=264.0.0&type=5
source_site: help.salesforce.com
content_type: documentation
content_hash: dcce88a0acd659433e475c4edeeba0229724f6f73b9f8ffc3330658e58523438
description: For the managed package runtime, looping calculations take a starting point, an endpoint, and an interval. At run time, the calculation procedure runs in a loop from start to end per interval. Each run uses the same input variables, plus an index variable that you can use in the calculation.
products:
  - Omnistudio
release: "264"
---
# The Looping Feature in Calculation Procedures (Managed Package)

For the managed package runtime, looping calculations take a starting point, an endpoint, and an interval. At run time, the calculation procedure runs in a loop from start to end per interval. Each run uses the same input variables, plus an `index` variable that you can use in the calculation.

![Managed Package app icon](https://sf-zdocs-cdn-prod.zoominsoftware.com/tdta-xcloud-omnistudio_for_managed_packages-264-0-0-production-enus/aa2554ec-624a-4ee6-8da4-6435670e6e62/resources-global/_corporate/images/managedpackageicon.png) This information is for Omnistudio for Managed Packages. For Omnistudio on standard runtime, see [Omnistudio Help](https://help.salesforce.com/s/articleView?id=xcloud.os_omnistudio_standard.htm&language=en_US).

Calculation procedures support looping calculations starting in the Vlocity Insurance Winter '18 Major Release.

For example, you can create a looping calculation procedure for a life insurance policy. The looping calculation procedure calculates the policy value for each year from the current age of the policy holder to the policy holder's age at the end of the policy term. The calculation takes a current age (35 years), end age (65 years), and an interval of 1 to calculate on an annual basis. The calculation runs, looping 30 times. All input variables remaining constant, but the index starts at 35 and increments by one through 65. The output shows the user the value of the policy each year from the start date to the end of the term.

To set up looping, see [Configure a Calculation Procedure for Looping (Managed Package)](https://help.salesforce.com/s/articleView?id=xcloud.os_configure_a_calculation_procedure_for_looping.htm&release=264.0.0&type=5 "For the managed package runtime, make sure that your calculation procedure UI is set up for looping calculations, then configure looping variables.").

## Index Variable

The `index` variable becomes available when you set Enable Looping on the Calculation Procedure Version. To add it to calculation steps, type `index` in a calculation step.

When a calculation procedure has looping set up and enabled, it increments `index` based on the looping `Interval` variable (whatever you've named it), from looping start until looping end. You can then use `index` to change the calculation on each looping pass. For example, you can add it to an `Age` to increment the value of `Age` for each loop.

![Note](https://sf-zdocs-cdn-prod.zoominsoftware.com/tdta-xcloud-omnistudio_for_managed_packages-264-0-0-production-enus/aa2554ec-624a-4ee6-8da4-6435670e6e62/images/icon_note.png)

Note

The system-provided `index` variable does not show up in the list of variables. You don't need to create it.

In this example, calculation step 3 is set up to calculate the year of the policy, looping per interval (one year). Step 4 calculates the age of the policy holder, looping per interval (one), starting with the policy holder's age at the start of the policy.

![The first three steps perform calculations. The first step sets AGEON(Birthdate,EffectiveDate) to startAge. The second step sets startAge + Term to endAge. The third step sets startAge + index to currentAge. The fourth step calls the currentMortality matrix, with input variables of currentAge and Gender and an output variable of currentDeathProbability.](https://sf-zdocs-cdn-prod.zoominsoftware.com/tdta-xcloud-omnistudio_for_managed_packages-264-0-0-production-enus/aa2554ec-624a-4ee6-8da4-6435670e6e62/omnistudio_for_managed_packages/images/calcprocedure_loopingcalcsteps.jpg)

## PREVIOUS Function

You can use the `PREVIOUS` function to get the previous looped iteration's result. The calculation step can use this function to access a previous iteration's variable results and calculate it with other variables.

`PREVIOUS` accepts the following:

- Variable name
    
    Usually set up as a constant of type `Text`
- `previousIterator`
    
    The index of the previous iteration result set from which to get the value for the variable
- `ITERATION`
    
    System-provided variable for accumulated results

In this example, the `PREVIOUS` function uses previous iterations to calculate the cash value of the policy per iteration (one).

![There are two calculation steps. The first sets PREVIOUS(cashValueName,1,ITERATION) \* dividendRate to intervalDividend, and the second sets PREVIOUS(cashValueName,1,ITERATION) + PREVIOUS(intervalDividendName,1,ITERATION) + PREVIOUS(cashInvestmentName,1,ITERATION) to cashValue.](https://sf-zdocs-cdn-prod.zoominsoftware.com/tdta-xcloud-omnistudio_for_managed_packages-264-0-0-production-enus/aa2554ec-624a-4ee6-8da4-6435670e6e62/omnistudio_for_managed_packages/images/calcprocedure_loopinguseprevious.jpg)

## Example 1: Calculation Procedure Simulation

For this example, the term = 2 (years), the start = 0 (year zero of the term), and the increment = 1 (year).

![Simulation input variables: Birthdate is 12/01/1970, effectiveDate is 12/07/2017, Term is 2, Gender is Female, FaceAmount is 3000, Premium is 3000, Start is 0, and Interval is 1.](https://sf-zdocs-cdn-prod.zoominsoftware.com/tdta-xcloud-omnistudio_for_managed_packages-264-0-0-production-enus/aa2554ec-624a-4ee6-8da4-6435670e6e62/omnistudio_for_managed_packages/images/calcprocedure_loopingsimulationoptions.jpg)

The output JSON for this simulation is:

```
{
   "output": [
      {
         "calculationResults": [
            {
               "index": 0,
               "intervalNumber": 0,
               "deathBenefit": 3000,
               "deathBenefitGuaranty": 3000,
               "cashValue": 0,
               "intervalDividend": 0,
               "cashInvestment": 2995.83,
               "cashInsurance": 4.17,
               "deathProbability": 0.00139,
               "currentMortality__currentDeathProbability": 0.002402,
               "currentAge": 47,
               "intervalDate": "2017-12-07",
               "endAge": 52,
               "ID": "input"
            },
            {
               "index": 1,
               "intervalNumber": 1,
               "deathBenefit": 5995.83,
               "deathBenefitGuaranty": 3000,
               "cashValue": 2995.83,
               "intervalDividend": 0,
               "cashInvestment": 2996.52,
               "cashInsurance": 3.48,
               "deathProbability": 0.00116,
               "currentMortality__currentDeathProbability": 0.002639,
               "currentAge": 48,
               "intervalDate": "2018-12-07",
               "endAge": 52,
               "ID": "input"
            },
            {
               "index": 2,
               "intervalNumber": 2,
               "deathBenefit": 8992.35,
               "deathBenefitGuaranty": 3000,
               "cashValue": 5992.35,
               "intervalDividend": 44.94,
               "cashInvestment": 2997.33,
               "cashInsurance": 2.67,
               "deathProbability": 0.00089,
               "currentMortality__currentDeathProbability": 0.002903,
               "currentAge": 49,
               "intervalDate": "2019-12-07",
               "endAge": 52,
               "ID": "input"
            }
         ],
         "aggregationResults": {}
      }
   ]
}
```

## Example 2: Omniscript

In this example, the looping calculation procedure is added to an Omniscript as a Calculation Action.

![OmniScript Calculation Action properties: Element Name is calcIllustration, Label is Calculate, Remote Class is vlocityins2.PricingMatrixCalculationService, Remote Method is calculate, Configuration Name is wholeLife, Include Inputs is checked, Pre-Transform DataRaptor Interface is WholeLife-Illustration-Pre, and Post-Transform DataRaptor Interface is WholeLife-Illustration-Post.](https://sf-zdocs-cdn-prod.zoominsoftware.com/tdta-xcloud-omnistudio_for_managed_packages-264-0-0-production-enus/aa2554ec-624a-4ee6-8da4-6435670e6e62/omnistudio_for_managed_packages/images/calcprocedure_loopingcalcinos.jpg)

The looping calculation creates a list of results. You can display these results in a format of your choice. In the example below, a custom template displays the results in a table that shows the values of the policy year over year (incremented by 1).

![The OmniScript displays the results in a Table of Values. The Year column has values blank, then 1 through 13. The Age column has values 48 through 61. The Guaranty Death Benefit column has the value 500000 in every cell. Protection column values start at 5120 and end at 2855. Saving column values start at -4453 and end at -2188. The first cell in the Cash Value column is blank, then the values start at -4453 and end -49716.73. Total Death Benefit values start at 500000 and end 450283.27.](https://sf-zdocs-cdn-prod.zoominsoftware.com/tdta-xcloud-omnistudio_for_managed_packages-264-0-0-production-enus/aa2554ec-624a-4ee6-8da4-6435670e6e62/omnistudio_for_managed_packages/images/calcprocedure_loopingcalctable.jpg)