Calculated Values
The Calculated Value feature is divided into 2 types: numeric and text calculated values. The numeric calculated value allows you to perform mathematical calculations using data from the submitted answers. Use the text calculated value to perform mathematical calculations and string together multiple answers into a single text string.
Numeric calculated values are applicable to the Single Line Text and the Numeric Allocation question types only.
Text calculated values can only be applied to the Single Line Text question type.
We don't recommend implementing calculated value to the answer options of Single Line Text question where the different formats are set as a referenced answer option can't accept the value of inappropriate format.
The article describes how to use the feature and adjust its settings.
How to set up the feature
Go to the Edit question page.
Specify the answer option that will store the data. Click the wrench icon on the right side of the answer field.
In the dropdown menu under the Calculated Value field, select Number for math calculations or Text for text calculations (strings). Insert your expression in the field on the right.
Note that the field for the calculation expression input is limited to 1024 characters;
Numeric calculated values
You can use formulas to make mathematical calculations based on the submitted answers. Values obtained may be used later in answer options or presented as the results to respondents in the same form.
Using values defined via Branch on Range
You can reference questions with the answer options for which the values were set using the Branch on Range logic type. You must use the format: Qx, Qx,Ay, Qx,Ay,Cz.
The allowed question types together with the expected behavior are shown in the table below:
Pick One or Other Pick One with Comment Dropdown Box | Qx: This reference will be replaced with the score value of the answer option chosen by a respondent. If the question is not answered, it will be replaced with 0 (zero). Qx.Ay: This reference will be replaced with the score value of the answer option only if this answer was selected; if it wasn't, then the value will be set to 0 (zero). |
---|---|
Check All That Apply List Box | Qx: This reference will be replaced with the score value of all the answer options selected by a respondent. If no options were selected, the value will be set to 0 (zero). Qx.Ay: This reference will be replaced with the score value of the answer option only if the answer option has been selected, if not, it will be replaced with 0 (zero). Note: If the score value of at least one answer option hadn't been assigned via Branch on Range logic and this answer option has been selected the value of all question will be replaced with 0 (zero). |
Rate Different Items Along the Scale | Qx: This syntax will always be replaced with zero Qx.Ay: This reference will be replaced with the score value of the column (Scale option) for this specific row. Qx.Ay.Cz: When referring to a certain column of an answer option, the reference will be replaced with the score value of that column only if this option is chosen for a certain row of the reference, if not, it will be replaced with 0 (zero). |
Mathematical operations and numbers
The following math operations can be performed (using the algebraic symbols shown in brackets):
Addition (+);
Subtraction (-);
Multiplication (*);
Division (/);
Numbers (positive and negative, integer and decimal).
ℹ Example:
(Q2 + Q5 + Q6) + 5*Q3.A1 - 100*(Q7.A5.C1+Q8.A9) + 0.5*Q6.A1
Using SCORE, MAXSCORE
SCORE (x,y): This formula calculates the score value of all questions in the interval from x to y, where 'x' and 'y' are the question numbers referring to the beginning and the end of the interval respectively. The SCORE(x,y) value is calculated by adding the score values of all questions within the range, including the score value of x and y. The syntax is case sensitive and must match the format.
If a multiline question has an undefined score and a user chooses it, the whole question will be excluded from calculations.
MAX_SCORE (x,y): This formula calculates the maximum amount of points that could have been scored in the interval from x to y, regardless of the actual responses. The 'x' and 'y' are the question numbers referring to the beginning and the end of the interval respectively.
The MAX_SCORE formula calculates the score value of questions that have been answered.
However, if a responder doesn't answer a multi-select answer option question type (e.g., Check All that Apply / Listbox / Compare One against Another), it means they chose the 'none of the answer options.' option. In this case, the MAX_SCORE formula will be calculated. If a responder doesn't answer a single answer option question type (Pick One or Other, Dropdown Box), it means the question was skipped and the MAX_SCORE formula will not be calculated.
Both formulas should match the syntax as shown below:
ℹ Example:
(SCORE(2,4)/MAX_SCORE(2,4))*100 = the percentage of of the maximum score obtained by the respondent.
If you are using the 2 formulas in your form for calculations, be sure not to use the same syntax (SCORE, MAX_SCORE) as question/answer identifiers, as this will interfere with the system behavior.
JavaScript Math library
You can use the Javascript Math methods to perform advanced calculations. There are 2 articles that can help you with the Javascript Math library: MDN Web Docs: Math and JavaScript Math Object.
You can use the JavaScript Math method with only 2 arguments.
If you want to use more than 2 arguments, please rewrite the formula as Math.min( Math.min( Math.min( Q1.A1, Q1.A2 ), Q1.A3 ), Q1.A4 ).
Using piping for calculations
You can use piping to calculate 'real-time' values using the formulas provided by the form administrator.
See the question types that can be used along with the expected behavior below:
Single Line Text / Numeric Allocation | Qx.Ay: The numeric value inserted into this field will replace the piping reference when the calculation is executed. If some text is inserted instead of a number, the formula will ignore it; this can be avoided by setting the preformats that only allow respondents to enter numeric values. |
---|---|
Object Lookup | Qx.Ay (refer to a column with the numeric format only): For an object lookup question to be used in a numeric calculated value, it must have a column with numeric format. When an object from the data model is chosen by the respondent, the numeric value in the column Ay for the chosen object will replace the reference in the formula. |
Matrix | Qx.Ay.Cz: This piping reference must refer to a text field. The value entered in this field will replace the piping reference when the calculation is executed. |
Decimal numbers in calculations
Some calculations may result in a value with a lot of decimal places, and such values are limited to 12 decimal places. As a workaround, you may apply the numeric format or the decimal number format with the needed number of decimal places to the answer field.
Text Calculated Values
You can use the text calculated values to copy answer options, create new answers based on the answers provided by respondents (thus adding several answer options into one).
The rules for composing formulas for text calculated values:
Symbols: You may use any symbols such as punctuation marks, text, numbers, mathematical operation signs.
Piping references: You may use piping tokens only with curly brackets for text calculated values, i.e. {Q1.A1} or {Q2}. Depending on the question type, the piping will work the following way:
Pick One or Other | Qx: The label of the answer option selected will be used in the calculated value. Qx.Ay: The label of the answer option referenced will be used in the calculated value if selected as an answer by a respondent. |
Pick One (Radio Buttons) | Qx: The label of the answer option selected and comment field separated by a comma will be used in the calculated value. Qx.Ay: The label of the answer option referenced will be included in the calculated value if selected as an answer by a respondent. |
Check All that Apply / Dropdown Box / List box | Qx: The labels of all the selected answer options separated by a comma will be used in the calculated value. Qx.Ay: The label of the answer option referenced will be included in the calculated value if selected as an answer by a respondent. |
Single Line Text | Qx: The text added to all the answer fields will be used in the calculated value. Qx.Ay: The text added to the referenced answer option field will be used in the calculated value. |
Multiline Text | Qx: The text inputted into the answer field will be used in the calculated value. |
Rating Scale | Qx: The labels of the selected answer options will be used in the calculated value. Qx.Ay: The label of the selected column in piped answer option. Qx.Ay.Cz: The label of the referenced column from the answer option will be used in the calculated value if selected as an answer by a respondent. |
Matrix | Qx / Qx.Ay: Such types of reference will be ignored. Qx.Ay.Cz: The label of the column or inputted text if referenced answer option will be used in the calculated value. |
Numeric Allocation | Qx: Inputted into answer options numbers and total value will be used in the calculated value. Qx.Ay: Value from the referenced answer option will be used in the calculated value. |
Object Lookup | Qx.Ay: When an object from the data model is chosen by the respondent, the value from the column Ay for the chosen object will replace the reference in the formula. |
Using the Skip Logic
Please note that if the Skip logic were set up in the form, the questions that get skipped when the logic сonditions are met will not be included in the calculation formula.