Advanced Expression Piping
Help Center

FluidSurveys Help > Building Surveys or Polls > Advanced Survey Features

Advanced Expression Piping

Advanced expression piping (AEP) lets you perform math operations in your survey, display the output to your respondents, and record it in your responses. Use AEP to do things like:

  • Calculate a score for a quiz
  • Perform calculations on values your respondents enter into your survey
  • Trigger advanced branching logic

AEP lets you create expressions that use operators or functions to evaluate or manipulate data input into your survey by respondents or passed through meta variables. Add AEP expressions syntax as the Hidden Value in a hidden field question type to record the result of your expression in your responses or use the output to trigger branching logic.

AEP Syntax:

{{ expression }}

Manipulating Respondent Input and Answer Selections

Use the answers to your questions as operands and parameters in your expressions.

When you use a question identifier in an expression, the value of the answer your respondent selects or inputs is piped into the expression. The example syntax in this article uses the following identifiers: q1, q2, and q3.

If your question allows multiple choices to be made, for example, a checkbox question, a grid question, or a 3D Matrix, the expression will be passed a comma separated list of selected values. If you would like to manipulate a single value from a grid question, you will need to use indexing to specify which value the expression should use.

TIP! If you are using AEP on an open ended question to perform numeric calculations, add validation to the question to require that your respondents enter numbers into your text boxes.

Indexing in Grids and the 3D Matrix

The syntax to index a particular row in a grid question is: identifier[index] where identifier is the question’s identifier and position is an integer indicating the index position of the row. Indexing begins at 0. So the first row in a question can be indexed with q1[0], the second row with q1[1] and so on.

The 3D Matrix has rows AND columns. Where grid questions begin their index at the top and move downwards, 3D Matrix questions being their index in the first row and first column, move left to right across each row, and down to the next row. In a 3D Matrix question with two rows and two columns, q1[3] would index the answer chosen in the second row and second column.

To index a single column in a 3D matrix, use identifier[:columnIndex] where 'identifier' is a question identifier and 'columnIndex' is an integer indicating the index position of the column.  q1[:0] returns a comma separated list of all values in the first column of q1.

To index a single row in a 3D matrix, use identifier[rowIndex:] where 'identifier' is a question identifier and 'rowIndex' is an integer indicating the index position of the row. q1[0:] returns a comma separated list of all values in the first row of q1.

Indexing a Range

The syntax to index a range is identifier[lower:upper] where 'identifier' is the question identifier, 'lower' is an integer specifying the index position the range should start at, and 'upper' is an integer specifying the index position where the range should end. Range indexing is lower bound inclusive and upper bound exclusive. This means that your returned values include the value at the position of your lower bound and exclude the value at the position of your upper bound. If you have a 4 row grid question, q1[0:3] will give you the first three values and q1[0:4] will give you all four.

Using the Score of the Selected Answer

The syntax to reference the score of a selected answer rather than the answer itself is identifier.score where 'identifier' is the question’s identifier. You can use score with indexing as well. q1.score[2] gives you the score of the third row in a grid question.

Meta Variables

Any of the meta variables available in the piping wizard can be used in your expressions. For example, pass in a GET variable value.

See List of Meta Variables
Meta VariableDescription
identifier.scoreWhere “identifier” is the identifier to your question. Uses the score of the selected answer in your expression
get_variable.getVariableNameWhere getVariableName is the name of your GET variable. Uses the value passed through your GET variable in the expression.
invite.emailUses the respondent’s email address in your expression. Only applicable if the survey is sent with the invite tool and your expression accepts strings.
invite.first_nameUses the respondent’s first name in your expression. Only applicable if the survey is sent with the invite tool and your expression accepts strings.
invite.last_nameUses the respondent’s last name in your expression. Only applicable if the survey is sent with the invite tool and your expression accepts strings.
invite.full_nameUses the respondent’s full name in your expression. Only applicable if the survey is sent with the invite tool and your expression accepts strings.
 

Creating Expressions with Operators and Functions

There are a variety of operators an functions available to manipulate your data and create simple or complex expressions. For example if you wanted to branch based on whether or not your respondents got a high enough score on a given page you could add a hidden field to the end of the page containing your scored question and add the following syntax to its Hidden Value:

{{ SUM(q1.score + q2.score + q3.score + q4.score + q5.score) >= 3 }}

Then add and advanced branching rule to branch based on whether the expression evaluates to true or false. The above expression evaluates to true if the sum of the question's scores is greater than or equal to 3.

Click below to see available operators and functions:

Available Operators
OperatorDescriptionExample SyntaxExample Description
+Performs addition{{ q1 + q2 }}Sums the values entered into two questions.
-Performs subtraction{{ q3[0] - q3[1] }}Subtracts the input in the second text box from the first input
*Performs multiplication{{ q1 * q2 }}Multiplies the value entered in q1 with the input into q2
/Performs division{{ q1 / q2 }}Multiplies the value entered in q1 with the input into q2
notPerforms boolean logic and evaluates to true or false.{{ not (q1 = 3 ) }}Evaluates to true unless a 3 is entered into q1.
andPerforms boolean logic and evaluates to true or false.{{ (q1 > 0) and (q1 < 11) }}Evaluates to true when a value between 1 and 10 is entered into q1
orPerforms boolean logic and evaluates to true or false.{{ (q1 > 0) or (q2 > 0) }}Evaluates to true when a value above 0 is entered into q1 or q2
=Is equal to. Evaluates to true or false.{{ q1 = q2 }}Evaluates to true when the input to q1 is the same as the input to q2.
>Is greater than. Evaluates to true of false.{{ q1 > q2 }}Evaluates to true when the input to q1 is greater than the input to q2.
<Is less than. Evaluates to true or false.{{ q1 < q2 }}Evaluates to true when the input to q1 is less than the input to q2.
>=Is greater than or equal to. Evaluates to true or false.{{ q1 >= q2 }}Evaluates to true when the input to q1 is greater than or the same as the input to q2.
<=Is less than or equal to. Evaluates to true or false.{{ q1 <= q2 }}Evaluates to true when the input to q1 is greater than or the same as the input to q2.
!=Does not equal. Evaluates to true or false.{{ q1 != q2 }}Evaluates to true when the input to q1 is not the same as the input to q2.
Available Functions
FunctionDescriptionExample
SUM(list)Accepts and sums a list of float or int parameters.{{ SUM(q1.score,q2.score,q3.score) }} Sums the scores of three questions
MAX(list)Accepts a list of float or int parameters and returns the largest one.{{ MAX(q1[0:4]) }} Returns the largest value entered in the first four rows of q1
MIN(list)Accepts a list of float or int parameters and returns the smallest one.{{ MIN(q1[0:4]) }} Returns the smallest value entered in the first four rows of q1
AVG(list)Accepts a list of float or int parameters and averages them.{{ AVG(q1,q2,q3) }} Averages the input of three questions
CONCAT(list)Accepts a list of parameters and concatenates them. Accepts strings.{{ CONCAT(q1[0:4]) }} Concatenates the input to the first four rows of q1
COALESCE(list)Accepts a list of parameters and returns the first one with a value in it.{{ COALESCE(q1[0:4]) }} Returns the first input value in the first four rows of q1
INT(float)Accepts a single float parameter and converts it into an integer.{{ INT(q1.score) }} Converts the score of q1 into an integer. So a score of 1.0 would become 1
STR(param)Accepts a single parameter and converts it into a string.{{ STR(q1) }} Converts the input of q1 into a string
REAL(int)Accepts a single int parameter and converts it into a real or floating point number.{{ REAL(q1) }} Converts the input of q1 into a floating point. So 1 would become 1.0
PRECISION(param, int)Accepts two parameters the second of which is an integer indicating the precision to calculate the first parameter.{{ PRECISION(q1/q2, 2) }} Divides the input of q1 by q2 and returns a value calculated to the the second decimal point. So if q1 = 1 and q2 = 3 it would return 0.33
RANDINT(min, max)Accepts two integers and generates a random number that is between them.{{ RANDINT(1,100) )) Returns a random value from between 1 and 100 inclusive.
INDEXOF(string, string)Accepts two string parameters and returns the index of the second parameter within the first parameter. If the second parameter is not found in the first, it will return –1. For example, if it were passed ‘example’ and ‘x’ it would return 1.{{ q1, ‘@’ }} Returns an index position of ‘@’ is entered into q1
SUBSTR(string, int, int)Accepts two or three parameters, the first a string, the second and third, integers indicating an index position. Returns the substring from the second parameter onward. If a third parameter is used, returns the substring between the two index positions (lower bound inclusive and upper bound exclusive).{{ SUBSTR(q1, 0, 4) }} Returns the first four characters entered into q1.