Calculated values
Work out numbers from other answers on an intake form with formulas.
Overview
A calculated field shows a number worked out from other answers on the form, such as annual cost from monthly cost, or cost per user. The submitter can't type into it. The value updates as they fill in the fields it reads.
Add a calculated field
- Add at least one Number field first. Formulas can only read number and calculated fields.
- In the Field types panel, open Advanced and click Calculated.
- Click the new field on the canvas and give it a Label.
- In the Calculated value section, click into Formula and type
{. A list of the fields you can use opens. Pick one with the mouse, or with the arrow keys and Enter. - Type the rest of the formula, for example
* 12. - Set Decimals, and a Prefix or Suffix if you want one.
- Check the line under the formula. It repeats the formula with field names, such as "= Monthly cost × 12", and shows the result with every input set to 1.
- Click Save.
Formula syntax
| You can use | Example | Notes |
|---|---|---|
| Numbers | 12, 0.5, .5 | No thousands separators or currency symbols. |
| Fields | Monthly cost | Inserted with {. Only number and calculated fields can be used. |
| Add and subtract | + - | |
| Multiply and divide | * / | Shown as × and ÷ in the summary line. |
| Parentheses | ( ) | Up to 20 levels deep. |
| Minus sign in front | -Discount | Makes the value that follows negative. |
Multiplication and division come before addition and subtraction. Otherwise the formula is worked out left to right, and parentheses change the order. Spaces are ignored. There is a length limit of 500 characters, counted on the stored formula, where each field takes about 30 characters. In practice that means about 15 fields in one formula.
If the formula has a mistake, the editor says what it found, such as "Unexpected end of formula" or "Expected ')'", and names the part just before the problem.
Which fields a formula can use
A formula can use any number or calculated field on the form, above or below it. A total at the top can add up fields further down. A calculated field can use another calculated field, so you can build a value in steps. The field list leaves out any field that already depends on this one, because using it would create a loop.
Decimals, prefix and suffix
- Decimals: A whole number from 0 to 6. Leave it empty for the default of 2. The result is rounded to this many places and always shown with them, so 4 with 2 decimals shows as 4.00.
- Rounding: Halves round away from zero: 2.5 becomes 3 and -2.5 becomes -3 with 0 decimals. 1.005 becomes 1.01 with 2 decimals.
- Prefix and suffix: Up to 10 characters each, shown before and after the number with a space, for example "€ 1,200.00" or "45 %". They are for display only and are not part of the stored value.
- Number format: Thousands separators and the decimal mark follow the language settings of the browser viewing the value.
When there is no result
The field shows a dash ("—") instead of a number when:
- An input field is empty or doesn't hold a number.
- An input field is hidden by its conditions. Hidden fields count as empty.
- The formula divides by zero.
- The result is too large to work with.
If an input the submitter can see is still empty, the public form names it under the dash, for example "Fill in Number of users to calculate". For a division by zero only the dash is shown.
What gets stored
VerifyWise doesn't trust the value worked out in the submitter's browser. When a submission arrives, it applies the formula again to the submitted answers and saves that result. Reviewers see the saved value with its prefix, suffix and decimals. A calculated field that is visible but has no result is saved as empty. A hidden calculated field is not saved at all.
What a calculated field can't do
- It can't be required, mapped to an entity field or tagged with a risk dimension. The builder hides these settings.
- It has no placeholder or guidance text. Help text is shown under the value.
- It can have its own conditions, and other fields' conditions can compare its value with =, ≠, >, ≥, < and ≤.
Checks before publishing
You can save a draft with an unfinished formula. You can't publish the form, or save changes to a published form, while a calculated field has one of these problems. The field is highlighted in the builder with the reason.
- The formula is empty or has a syntax error.
- The formula uses a field that was removed.
- The formula uses a field that is not a number or calculated field.
- The formula uses its own field, or two fields depend on each other in a loop.
- Decimals is not a whole number from 0 to 6.
- The prefix or suffix is longer than 10 characters.
Worked examples
| Goal | Formula | Settings and result |
|---|---|---|
| Annual cost | Monthly cost * 12 | Decimals 0, prefix €. A monthly cost of 1500 shows "€ 18,000". |
| Cost per user | Annual cost / Number of users | Decimals 2. Uses the annual cost field above. With 0 users the result is "—". |
| Share of users affected | Affected users / Total users * 100 | Decimals 1, suffix %. 250 of 2000 shows "12.5 %". |
| Average of three ratings | (Rating A + Rating B + Rating C) / 3 | Decimals 1. If any rating is empty, the result is "—". |
In the formula box, fields appear as chips with their labels. The examples above show the labels the same way.