Calculations
Last updated
Was this helpful?
Calculations are used to create hidden fields that automatically compute values based on other answers in the form.
In XLSForm, calculations are defined using the calculate question type. These fields are not shown to the user, but they run in the background and store results for later use or analysis.
In ngSurvey, calculated values will be saved as hidden fields and included in the form data output, just like other answers.
To create a calculation:
Use the type calculate in the survey sheet.
Assign a name to the field.
Use the calculation column to define the logic.
Optionally, use the label column for internal reference (it won’t be shown to the user).
integer
q1
integer
q2
integer
q3
calculate
total_score
${q1} + ${q2} + ${q3}
In this example:
The user answers three numeric questions (q1, q2, q3).
The total_score field adds those three values together.
The value of total_score is saved in the form data, even though it is never displayed.
You can use most standard operators and functions, such as:
Math: +, -, *, div, mod
Text: string-length(), regex, round, substr, concat
Logic: if(condition, true, false), coalesce()
Dates: today(), now(), date()
Last updated
Was this helpful?
Was this helpful?