Vault LIMS allows you to configure *Lab Result Definitions* as calculated results, populating the result value at runtime according to a formula you define in the result definition.

These calculation formulas can reference other results in the same *Lab Method*, results from other *Lab Methods*, or a centralized list of calculation constants. Static Data Admins accomplish this by first adding *Calculation Variables* to the result definition, targeting them to other results or constants accordingly, then referencing them in the calculation formula.

## Setting Up Calculated Results

To add a calculated *Lab Result Definition*:

- In a
*Lab Method*create a new*Lab Result Definition*of type**Numeric Result**. - In the
**Expected Data Entry Method**field, select**Calculation**. - Fill in the other fields as appropriate for the calculated result.
- Click
**Save**.

To add variables to a calculated *Lab Result Definition*:

- In the
*Calculation Variables*section of the*Lab Result Definition*record detail page, click**Create**. - Select a type from the drop-down:
**Method Variable**: The variable’s value is drawn from another result within the same Method.**Cross-Method Variable**: The variable’s value is drawn from a different*Lab Method*.**Constant**: The value of the variable is drawn from your Vault’s repository of established constants.

- Enter a
**Name**. The*Name*value for a variable can only be made of letters and numbers, and cannot contain spaces. - If you are creating a
*Method Variable*, select a**Target Result**from the other results available in the current*Lab Method*. - If you are creating a
*Cross-Method Variable*, select a**Result Type**. The target result for this variable is determined while adding*Lab Methods*to*Sample Definitions*in a*Lab Protocol*. - If you are creating a
*Constant*, select a**Target Constant**. - Click
**Save**.

Once you have created your variables, you can define the formula for the calculation.

### Defining a LIMS Calculation Formula

LIMS calculation formulas follow standard Vault formula construction with the following additions:

- Variable names are always preceded by a dollar sign (
`$`

). Typing $ will cause the formula builder to display all available variables for quick insertion. - You can click the
**Variables**tab to see all available variables.

For example, the formula `( $A1 - $B2 ) / $C3`

will divide the difference of the variable values `A1`

and `B2`

by variable value `C3`

.

**Note**: Ensure that you leave a space after the variable name so Vault LIMS can distinguish a variable from other characters in the formula.

## Calculation Constants

Vault LIMS allows you to manage a central library of constants for use in *Calculation Variables*. *Calculation Constant* records contain one or more *Constant Value* records, allowing calculation formulas to refer to the *Calculation Constant* and for Vault LIMS to automatically select the appropriate *Constant Value* according to the type of *Constant* (*Global* or *Material*) and *Material* on the *Batch*.

To create a *Lab Calculation Constant*:

- Navigate to a
**Lab Calculation Constants**object tab. - Click
**Create**. - Enter a
**Name**. - Select a
**Constant Type**:**Global**: Allows a single*Constant Value*.**Material**: Allows you to define a*Constant Value*per*Material*.

- Click
**Save**.

Once you have created your constant, add the appropriate constant value or values.

### Constant Values

Each *Lab Calculation Constant* must contain at least one (1) *Constant Value* in order to be used in a *Calculation Variable*. To create a *Constant Value*:

- In the
*Constant Value*section of a*Lab Calculation Constant*record detail page, click**Create**. - Enter a
**Name**. - Enter a
**Value**. - If you are creating a value for a
*Material*constant, select a**Material**record to associate it with. - Click
**Save**.

Global constants only contain a single *Constant Value*. Material constants can contain multiple values, but each must be associated with a specific *Material* record.

#### About Constant Value Versions

To ensure traceability, Vault LIMS automatically creates *Constant Value Version* records every time you edit a *Constant Value* record. When Vault LIMS selects a constant for a *Lab Result Variable*, it uses the latest *Constant Value Version* when passing the value into the result calculation. Because *Lab Result Variables* at *Lab Test* creation target specific *Lab Calculation Constant Value Version* records, you can freely update the *Value* field on the *Constant Value* record without affecting currently running *Lab Tests*.

## About Variable Dependency in Calculated Lab Results

When Vault LIMS creates *Lab Results* from *Lab Result Definitions*, it also creates *Lab Result Variables* based on the variables attached to each *Lab Result Definition*. Those *Lab Result Variables* target specific *Lab Results* (in the same *Lab Test* or from another *Lab Test*) or *Lab Calculation Constants* that will contain the values needed for the calculation.

Because *Lab Results* are only created when a *Lab Sample* enters the *Received* state type, which creates the *Lab Tests* from *Lab Methods*, and *Lab Results* from *Lab Result Definitions*, it’s possible that a cross-test *Lab Result Variable* is created before the *Lab Result* it’s targeting has been created. In that situation, Vault LIMS creates the *Lab Result Variable*, and when the necessary *Lab Result* is eventually created, Vault LIMS will target the *Lab Result Variable* accordingly.

## About Calculations in Test Execution

Calculated result values are generated when the *Lab Test* enters the *In Review* state type. When the Analyst clicks the **Review** button, Vault performs the following:

- Validates the calculation formula.
- Calculates the result.
- Evaluates the result against any existing specification criteria.

If Vault cannot resolve the calculation, or can’t put the value into the *Lab Result*, then the system captures the errors in the *Lab Result*’s *Save Errors* field.

If the calculated *Lab Result* is required, the Analyst cannot complete the *Lab Test* until a value has been populated into that *Lab Result*. If this occurs, check each of the *Lab Result*’s variables to see if there’s anything missing, or if the referenced *Lab Results* are not in the *Testing Complete* state type.

# Related Permissions

To view and manage calculation formulas, a user needs a permission set with *View* access to the *Calculation Formula* object control permission on the *Lab Result Definition* object.