Calculated fields allow a form to automatically perform mathematical operations using values from other fields. This can be useful for generating totals, scores, or other derived values without requiring manual entry.
For example, a Total Rating field could automatically add together values from an Academic Rating field and an Extracurricular Rating field.
Step 1: Configure the Fields Used in the Calculation
Before creating the calculated field, ensure that the fields providing the values are properly configured.
Each field should include the following:
Export Key
The export key is the internal reference used when building the calculation formula.
Use lowercase characters
Do not include spaces
Data Type
The field must use a numeric data type so that the values can be included in a calculation.
Int – used for whole numbers
Real – used for decimal values
Note:
If a non-numeric data type is selected, submitted values will be treated as text and concatenated rather than mathematically calculated.
Step 2: Create the Calculated Field
Next, create the field that will display the calculated result.
This field should be configured with:
An Export Key
A numeric Data Type
A Calculation Formula
The calculation formula defines the mathematical operation that Slate should perform.
Example
If the export keys for the rating fields are:
academic_ratingextracurricular_rating
The calculation formula would be: @academic_rating + @extracurricular_rating
When the form is submitted, Slate will add the values from these fields and display the result in the calculated field.
Supported Operators
Calculation formulas support standard mathematical operators:
Operator | Function |
|---|---|
| Addition |
| Subtraction |
| Multiplication |
| Division |
In addition to standard mathematical functions, all JavaScript mathematical functions are also supported. For example:
Standard Mathematical Functions |
|
|---|---|
Average | (@aca + @extra)/2 |
Multiple operators | ((3*@aca) + @extra)/2 |
Average with a consistent denominator | (@var1 + @var2 + var3) / 3 |
Average with a variable denominator If there are values in some but not all the variables in this formula, those will be averaged. There has to be a value in at least one of the variables. Otherwise, you'll get a divide-by-zero error; that's why variable 1 is assumed to be there (nothing conditional, just a literal 1 value), and only variables 2 and 3 will change the denominator based on if there's a value present or not. | (@var1 + @var2 + @var3) / (1 + ((@var2)?1:0) + ((@var3)?1:0)) |
Conditional Statements |
|
|---|---|
Example 1 Check if the variable has a numeric value greater than 0, not just any value. Place any valid calculation in the if-yes and if-no parts, but both must be present even if only to return nothing/an empty string. | (@variable > 0) ? (DO-THIS-IF-YES) : (DO-THIS-IF-NO) |
Example 2 Check if there's a value in the variable (numeric or text, doesn't matter) and if yes, return a 1. If no return a 0.
| @variable ? 1 : 0
|
Javascript Mathematical Functions |
|
|---|---|
Round up always | Math.ceil((@aca + @extra)/2) |
Round down always | Math.floor((@aca + @extra)/2) |
Round | Math.round((@aca+ @extra)/2) |
🔔 Important!If a string value is being translated, append the export key in the calculation formula with "_text".
In these cases, use the following format for the calculation formula: translate("key", @export_text)
Click here for a comprehensive list of available JavaScript Math Library Functions.