---
title: "Form calculation reference"
description: "Use field references, conditions and aggregate functions to produce checked form results."
url: https://helpcenter.complytrain.net/en/articles/165-form-calculation-reference
collection: "Forms and records"
updated: 2026-09-22
language: en
---

# Form calculation reference

Use field references, conditions and aggregate functions to produce checked form results.

Use field references, conditions and aggregate functions to produce checked form results.

A calculated field derives a result from other answers. Configure its Formula in the field editor and give the result a label and unit. Respondents change the inputs; the result is read-only.

## Refer to fields by code

Product location: `/qms/{standardCode}/forms/{templateId}/edit` (fallback: `/qms/standards`). Open the intended standard, choose Forms, then Edit Form on the accessible template.

Enclose a field code in braces, such as `{sample_count}`. Use the exact code from the form definition, including any suffix. A label such as “Number of samples” is not the code.

For estimated minutes at five minutes per sample, use `{sample_count} * 5`. Counts of `0`, `3` and `10` should produce `0`, `15` and `50`. These numbers illustrate the calculation; choose a factor appropriate to your process.

Keep referenced codes stable. Review dependent formulas before renaming or deleting their input fields.

![The formula multiplies the sample-count field by 5 to estimate the review duration in minutes.](https://staticfiles.gleap.io/p6950dfbf97796f2087a9f022/uXZPiqm2K6RhXGnSLkYIWyWHIu6Nqxt7Dzm96295jJgqeHRa4x7gUjlM9xIIbvvXENJjqSnROzc.png "Calculate estimated review time")

## Use arithmetic and parentheses

Product location: `/qms/{standardCode}/forms/{templateId}/edit` (fallback: `/qms/standards`). Open the intended standard, choose Forms, then Edit Form on the accessible template.

<table style="min-width: 75px;"><colgroup><col style="min-width: 25px;"><col style="min-width: 25px;"><col style="min-width: 25px;"></colgroup><tbody><tr><th colspan="1" rowspan="1"><p>Expression</p></th><th colspan="1" rowspan="1"><p>Meaning</p></th><th colspan="1" rowspan="1"><p>Example result</p></th></tr><tr><td colspan="1" rowspan="1"><p><code>8 + 2</code></p></td><td colspan="1" rowspan="1"><p>Addition</p></td><td colspan="1" rowspan="1"><p><code>10</code></p></td></tr><tr><td colspan="1" rowspan="1"><p><code>8 - 2</code></p></td><td colspan="1" rowspan="1"><p>Subtraction</p></td><td colspan="1" rowspan="1"><p><code>6</code></p></td></tr><tr><td colspan="1" rowspan="1"><p><code>8 * 2</code></p></td><td colspan="1" rowspan="1"><p>Multiplication</p></td><td colspan="1" rowspan="1"><p><code>16</code></p></td></tr><tr><td colspan="1" rowspan="1"><p><code>8 / 2</code></p></td><td colspan="1" rowspan="1"><p>Division</p></td><td colspan="1" rowspan="1"><p><code>4</code></p></td></tr><tr><td colspan="1" rowspan="1"><p><code>8 % 3</code></p></td><td colspan="1" rowspan="1"><p>Remainder</p></td><td colspan="1" rowspan="1"><p><code>2</code></p></td></tr><tr><td colspan="1" rowspan="1"><p><code>-2</code></p></td><td colspan="1" rowspan="1"><p>Negative value</p></td><td colspan="1" rowspan="1"><p><code>-2</code></p></td></tr><tr><td colspan="1" rowspan="1"><p><code>(8 + 2) * 3</code></p></td><td colspan="1" rowspan="1"><p>Evaluate the grouped expression first</p></td><td colspan="1" rowspan="1"><p><code>30</code></p></td></tr></tbody></table>

Use decimals where appropriate, such as `{quantity} * 2.5`. Parentheses help make the intended order explicit when combining operations. Check units as well as arithmetic: adding minutes to a sample count does not produce a meaningful result.

## Compare values and choose a result

Product location: `/qms/{standardCode}/forms/{templateId}/edit` (fallback: `/qms/standards`). Open the intended standard, choose Forms, then Edit Form on the accessible template.

Comparisons use `==`, `!=`, `<`, `<=`, `>` and `>=`. Use them as conditions in `if(condition, when_true, when_false)` or `condition ? when_true : when_false`.

For example, `if({sample_count} > 10, 30, 15)` produces `15` for ten samples and `30` for eleven. The equivalent expression is `{sample_count} > 10 ? 30 : 15`.

Use `true` and `false` for Boolean values and `!` to negate a Boolean condition. Keep complex business logic readable. A short nested `if` can express a second decision; review every branch with an example.

## Aggregate values

Product location: `/qms/{standardCode}/forms/{templateId}/edit` (fallback: `/qms/standards`). Open the intended standard, choose Forms, then Edit Form on the accessible template.

<table style="min-width: 75px;"><colgroup><col style="min-width: 25px;"><col style="min-width: 25px;"><col style="min-width: 25px;"></colgroup><tbody><tr><th colspan="1" rowspan="1"><p>Function</p></th><th colspan="1" rowspan="1"><p>Purpose</p></th><th colspan="1" rowspan="1"><p>Example</p></th></tr><tr><td colspan="1" rowspan="1"><p><code>min</code></p></td><td colspan="1" rowspan="1"><p>Lowest value</p></td><td colspan="1" rowspan="1"><p><code>min(2, 5, 3)</code> gives <code>2</code>.</p></td></tr><tr><td colspan="1" rowspan="1"><p><code>max</code></p></td><td colspan="1" rowspan="1"><p>Highest value</p></td><td colspan="1" rowspan="1"><p><code>max(2, 5, 3)</code> gives <code>5</code>.</p></td></tr><tr><td colspan="1" rowspan="1"><p><code>sum</code></p></td><td colspan="1" rowspan="1"><p>Total</p></td><td colspan="1" rowspan="1"><p><code>sum(2, 5, 3)</code> gives <code>10</code>.</p></td></tr><tr><td colspan="1" rowspan="1"><p><code>avg</code></p></td><td colspan="1" rowspan="1"><p>Arithmetic mean</p></td><td colspan="1" rowspan="1"><p><code>avg(2, 4, 6)</code> gives <code>4</code>.</p></td></tr><tr><td colspan="1" rowspan="1"><p><code>count</code></p></td><td colspan="1" rowspan="1"><p>Number of supplied values</p></td><td colspan="1" rowspan="1"><p><code>count(2, 4, 6)</code> gives <code>3</code>.</p></td></tr><tr><td colspan="1" rowspan="1"><p><code>product</code></p></td><td colspan="1" rowspan="1"><p>Product of the values</p></td><td colspan="1" rowspan="1"><p><code>product(2, 3, 4)</code> gives <code>24</code>.</p></td></tr><tr><td colspan="1" rowspan="1"><p><code>weighted_sum</code></p></td><td colspan="1" rowspan="1"><p>Sum of each value multiplied by its corresponding weight</p></td><td colspan="1" rowspan="1"><p><code>weighted_sum(4, 2, 0.75, 0.25)</code> gives <code>3.5</code>.</p></td></tr><tr><td colspan="1" rowspan="1"><p><code>if</code></p></td><td colspan="1" rowspan="1"><p>Select a result according to a condition</p></td><td colspan="1" rowspan="1"><p><code>if(3 &gt; 2, 10, 5)</code> gives <code>10</code>.</p></td></tr></tbody></table>

Arguments can contain field references and arithmetic, for example `sum({setup_minutes}, {sample_count} * 5)`. Supply meaningful inputs for the operation and verify the result for the intended range.

## Refer to repeating entries

Product location: `/qms/{standardCode}/forms/{templateId}/edit` (fallback: `/qms/standards`). Open the intended standard, choose Forms, then Edit Form on the accessible template.

A group reference includes the group code, an entry position or wildcard, and the member field code. For group `samples` and member `quantity`:

<table style="min-width: 50px;"><colgroup><col style="min-width: 25px;"><col style="min-width: 25px;"></colgroup><tbody><tr><th colspan="1" rowspan="1"><p>Reference</p></th><th colspan="1" rowspan="1"><p>Meaning</p></th></tr><tr><td colspan="1" rowspan="1"><p><code>{samples[0].quantity}</code></p></td><td colspan="1" rowspan="1"><p>Quantity in the first entry; positions start at zero.</p></td></tr><tr><td colspan="1" rowspan="1"><p><code>{samples[1].quantity}</code></p></td><td colspan="1" rowspan="1"><p>Quantity in the second entry.</p></td></tr><tr><td colspan="1" rowspan="1"><p><code>{samples[*].quantity}</code></p></td><td colspan="1" rowspan="1"><p>Quantities from all entries, for use in an aggregate.</p></td></tr></tbody></table>

With quantities `2`, `3` and `5`, `sum({samples[*].quantity})` gives `10`, `max({samples[*].quantity})` gives `5` and `count({samples[*].quantity})` gives `3`.

Complete the referenced member value in each relevant entry. Review what should happen when entries are added, removed or left incomplete. A wildcard identifies several values; an aggregate turns them into a single result.

## Calculate weighted results

Product location: `/qms/{standardCode}/forms/{templateId}/edit` (fallback: `/qms/standards`). Open the intended standard, choose Forms, then Edit Form on the accessible template.

For repeated factors with `score` and `weight`, use `weighted_sum({factors[*].score}, {factors[*].weight})`. Each score is multiplied by the weight in the corresponding entry, then the products are added.

For scores `4` and `2` with weights `0.75` and `0.25`, the result is `4 × 0.75 + 2 × 0.25 = 3.5`. For scalar arguments, list the values first and their corresponding weights second, as in `weighted_sum(4, 2, 0.75, 0.25)`.

Choose weights according to your methodology. This function calculates a weighted sum; if your intended measure is a weighted average, account for the total weight in the formula. Verify that values and weights correspond to the same entries.

## Handle zero and incomplete inputs deliberately

Product location: `/qms/{standardCode}/forms/{templateId}/edit` (fallback: `/qms/standards`). Open the intended standard, choose Forms, then Edit Form on the accessible template.

Zero is a numeric answer. An unanswered field is missing information. Decide which input questions are required and which have meaningful defaults instead of treating every missing value as zero.

Protect a division with an appropriate condition when the denominator can be zero. For example, if zero samples should mean zero minutes per sample, use `if({sample_count} == 0, 0, {total_minutes} / {sample_count})`. Choose that fallback only when it has the intended business meaning.

If a calculation cannot be evaluated, review the referenced codes, supplied values, group entries and arithmetic. A failed or absent result must be corrected before it is used as a score or mapped into a follow-up action.

## Combine calculations with conditional questions

Product location: `/qms/{standardCode}/forms/{templateId}/edit` (fallback: `/qms/standards`). Open the intended standard, choose Forms, then Edit Form on the accessible template.

If an input question becomes hidden, its retained answer is excluded from the submitted response and output processing. Design the calculated question's condition and inputs together so the result is based on the answers applicable to that response.

Test the full sequence: supply an input, review the result, change an earlier answer to hide the input and inspect the final submission. A previously entered hidden value must not determine a generated record or action.

## Validate a calculation before routine use

Product location: `/qms/{standardCode}/forms/{templateId}/edit` (fallback: `/qms/standards`). Open the intended standard, choose Forms, then Edit Form on the accessible template.

Write down representative inputs and expected results. Include ordinary values, zero, permitted negative or decimal inputs, each conditional branch and repeated-entry additions or removals.

Check the saved formula, preview result and submitted result. If the result drives an output rule, open the resulting record and compare the mapped value as well. ComplyTrain evaluates calculated values for the submitted response; verify the final saved result as part of the form's acceptance.

Use [the illustrated calculation editor](https://help.complytrain.net/en/qms/form-options-calculations/) for creation and [submission review](https://help.complytrain.net/en/qms/review-form-submissions/) for the response and its outputs.

![In the Sampling review step, 11 samples produce 55 estimated minutes and the explanation question is visible.](https://staticfiles.gleap.io/p6950dfbf97796f2087a9f022/2FHmC4XpN3dDG8OeOTBWR91OBp4ifPp8qvbVdgFr4ta8FZa1xmXutBX8UB0a29RdrQxZT2rnian.png "Inspect the respondent experience")
