1. Home
2. Survey
3. Build Survey
4. Calculations and Variables in Survalyzer
1. Home
2. Other Resources
3. FAQ
4. Calculations and Variables in Survalyzer

# Calculations and Variables in Survalyzer

In Survalyzer you can use calculations in filters and value assignments, where you can also use variables. Variables and their names can be defined by question code. More information can be found below.

### Calculations

You can add calculations with variables within filters, validation conditions and value assignments (see note below). If you choose the criterion “Calculation”, you’ll be able to set up a comparison of two expressions. Both expressions could be numbers, variables or calculations (with variables and numbers).
The following example shows the calculation of an average. A matrix question (with code q1) has three items (each in a its own row) which should be rated on a 5 point scale. If the participant makes a low average rating they will see the next question. The filter condition of the next question checks the average rating of the three items:

Calculations can be made using the four basic arithmetic operations: addition (+), subtraction (-), multiplication (*), division (/) and modulus (%).

Hint: What is modulos?
The modulo operation finds the remainder after division of one number by another. For example, “5%3 = 2” which means 2 is the remainder when you divide 5 by 3.

Brackets can be used to define prior operations. Possible variables are survey variables (question codes), panel variables (panel fields) and URL variables (which come from URL parameters added to the questionnaire link), and which can be used in calculations.

NOTE (Survalyzer NG): If you calculate values within a value assignment, you must not use the double curly brackets ({{}}) around each variable name (“{{variable_name}}”). Example: ({{q1}}+{{custom.average}})/2

### Variables

Question variables make use of question codes. Whenever a question requires more than one variable (e.g. a multiple response or matrix question), the answer options will be added with the code of that option which follows a preceding underscore. Text fields in half open questions are addressed with _text. In the following, we explain how to find the correct variable for each question type:

Single Choice, Drop-Down, Discrete Slider, Open Question

For these question types, it’s simple to get to the variable name. The question code is always the variable name.

For all question types, you can see the variable name in the upper left corner of the element on the build page of your survey. This also includes the email and date question type.

Explanation: QuestionCode
Value: ChoiceCode

Multiple Choice

In a multiple choice question each choice represents a variable which either contains a value of 0 (unchecked) or 1 (checked), depending on which element the respondent checked. The variable name combines the question code and the code of choice.

So, for the first two choices, the variables would be:
Choice 1: q5_1
Choice 2: q5_2
and so on…

Explanation: QuestionCode_ChoiceCode
Value: 0 (unchecked) or 1 (checked)

Standard Matrix Single Choice / Semantic Differential

A standard matrix single choice question does not have column groups and is set as a single choice or drop down. In this case, each row represents its own variable. The variable name combines the question code and the code of the row.

So, for the first two rows, this would result in the following variables:
Row 1: q6_1
Row 2: q6_2
and so on…

Explanation: QuestionCode_RowCode
Value: ChoiceCode

Standard Matrix Multiple Choice

A standard matrix multiple choice question does not have column groups and is set as multiple choice. In this case, each option in each row represents one variable. The variable name combines the question code, the code of the row and the code of the option.

So, for the first two options in the first row, this would result in the following variables:
Option 1: q7_1_1
Option 2: q7_1_2
and so on…

The first two options in the second row, would result in the following variables:
Option 1: q7_2_1
Option 2: q7_2_2
and so on…

Explanation: QuestionCode_RowCode_ChoiceCode
Value: 0 (unchecked) or 1 (checked)

Matrix Question with column groups

A column group adds a layer to the matrix question, resulting in an even longer variable name. Column groups get numbered in the same order they appear in the UI. The variable name combines the question code, the code of the row, the number of the column group and the code of the option.

So, the first two options in the first row, in the first column group (multiple choice) would result in the following variables:
Option 1: q7_1_1_1
Option 2: q7_1_1_2
and so on…

Explanation: QuestionCode_RowCode_ColumnGroupNumber_ChoiceCode
Value: 0 (unchecked) or 1 (checked)

The first column group (single choice, drop down) would result in the following variables (variables get set up to step 3 in the picture):
Row 1: q7_1_1
Row 2: q7_2_1
and so on…

Second column group:

Row 1: q7_1_2
Row 2: q7_2_2
and so on…

Explanation: QuestionCode_RowCode_ColumnGroupNumber
Value: ChoiceCode

Rank Order

The Rank Order question results in one variable for each item. The value is defined by the chosen rank which is saved within this variable. The variable name combines the question code and the code of the item.

So, for the first two items, the variables would be:

Item 1: q8_1
Item 2: q8_2
and so on…

Explanation: QuestionCode_ItemCode
Value: Rank

Semi Open Questions

Semi open text fields are addressed with _text. “_text” will be added to the corresponding variable name. How to find the corresponding variable name can be found at the question variable explanation on this site.

Example: q1_1_text
Explanation: QuestionCode_ChoiceCode_text

Example: q2_1_text
Explanation: QuestionCode_ChoiceCode_text

Example: q6_1_text
Explanation: QuestionCode_RowCode_text

Example: q6_1_1_text
Explanation: QuestionCode_RowCode_ColumnCode_text

Example: q6_1_1_1_text
Explanation: QuestionCode_RowCode_ColumnGroupNumber_ColumnCode_text

Value of a filtered (not shown) question / choice

The value of a question or a choice that was filtered (i.e. not shown to the respondent) is always 0.

Custom Variable

Custom variables can also be used. Just use the prefix “custom.”.

Example: custom.variable_name

Panel Variable

Panel variables can also be used. Just use the prefix “panel.”.

Example: panel.age

URL Variable

URL variables can also be used. There are 20 URL variables, numbered and pre-defined (url.var01, url.var02 etc.). To use them just add the prefix “url.”.

Example: url.var01

Updated on May 20, 2022