Background Calculations
Custom variables serve as intermediate or auxiliary variables that perform various calculations in the background within the survey's JSON schema as respondents answer questions. These calculations are based on expressions and support built-in and custom functions. In this demo, background calculations are used to combine a full name from the provided first and last names and to calculate a respondent's age based on their birthdate.
To create a custom variable for background calculations, populate the SurveyModel
's calculatedValues
array with objects of the following structure:
{
name: string; // A name that identifies the calculated value.
expression: string // An expression that returns the calculated value.
includeIntoResult: boolean; // Specifies whether to include the calculated value in survey results.
}
Calculated values can be used in display texts and expressions. In this demo, for instance, calculated values are displayed within an HTML element of a survey.