Calculations
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.
🔢 How to define a calculation
To create a calculation:
Use the type
calculatein thesurveysheet.Assign a name to the field.
Use the
calculationcolumn to define the logic.Optionally, use the
labelcolumn for internal reference (it won’t be shown to the user).
Example: Total score from multiple answers
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_scorefield adds those three values together.The value of
total_scoreis saved in the form data, even though it is never displayed.
Useful calculation functions
You can use most standard operators and functions, such as:
Math:
+,-,*,div,modText:
string-length(), regex, round, substr, concatLogic:
if(condition, true, false),coalesce()Dates:
today(),now(),date()
Last updated
Was this helpful?