m

Advanced Piping: Math Operations & Advanced Functions

This add-on extends the capabilities of Advanced Piping so you can perform math operations and advanced functions with respondent data, and pipe the output into your survey.

Writing Advanced Piping Expressions

You can use a variety of operators and functions to create simple or complex expressions based on any of the data sources available.

You can insert an Advanced Piping expression into your survey by placing it within double curly braces in any supported field:

{{ expression }}

When a respondent takes your survey, the output of the expression will replace the brackets based on their unique answers, or the custom data or custom variables associated with them.

The sections below explains the notation and syntax you can use to write advanced piping expressions in your survey.

Data Sources

Learn the notation you need to use to reference questions, custom variables, and custom data from Contacts in the Advanced Piping expressions you write.

Notation for Referencing Questions

A question number is determined by its position in your survey, starting at 1. The question number is unaffected by the question numbering option that's enabled.

For example, here's the syntax you would use to insert the respondent's answer to question 1:

{{ Q1 }}

For questions with multiple rows, multiple columns, or "Other" comment fields, you can use the following notation to specify the row, column, or field you wish to pipe from.

Example Notation
Example Output
Applicable Question Types
Q1The respondent's answer to question 1.Any question type that collects data (excludes Text, Image, Text A/B Test, and Image A/B Test).
Q1.R2The respondent's answer to the second row of question 1.Any question type with multiple rows, like Multiple Textboxes.
Q1.C3The respondent's answer to third column of question 1.Matrix/Rating Scale
Q1.R1.C2The respondent's answer the respondent selected from the dropdown in the second column of the first row in question 1.Matrix of Dropdown Menus
Q1.OTHERThe respondent's open-ended answer to the "Other" Answer Option for question 1.Multiple Choice, Dropdown, and Matrix/Rating Scale questions with an "Other" Answer Option for Comments
Q1.R2.OTHERThe respondent's open-ended answer to the comment box for the second row of question 1.Matrix/Rating Scale questions with an "Other" Answer Option for Comments AND "One comment per row" selected.
Q1.R1 = NAThe N/A column label.Matrix/Rating Scale questions with an N/A column.
Notation for Referencing Custom Data from Contacts

You can pipe custom data from Contacts into your survey using the following notation:

Notation
Description
contact.first_nameThe value of the First Name filed in Contacts.
contact.last_nameThe value of the Last Name field in Contacts.
contact.emailThe value of the Email Address field in Contacts.
contact.custom1The value of the Custom 1 field in Contacts.
contact.custom2The value of the Custom 2 field in Contacts.
contact.custom3The value of the Custom 3 field in Contacts.
contact.custom4The value of the Custom 4 field in Contacts.
contact.custom5The value of the Custom 5 field in Contacts.
contact.custom6The value of the Custom 6 field in Contacts.

For example, here's the syntax you would use to insert the value of the Custom 2 field associated with the respondent in your Contacts.

{{ contact.custom2 }}

For Custom 1-6 fields, the notation remains the same even if you created custom label names for those fields.

Learn more about managing Custom Data: Using Custom Data to Store Contact Info

Notation for Referencing Custom Variables

You can pipe custom variables into your survey using the following notation:

Notation
Description
custom.variable_nameReplace variable_name with the Variable Name you assigned to the custom variable in the Design Survey section.

For example, if you have a custom variable with the Variable Name "department", here's the syntax you would use to insert the value of that custom variable into the survey:

{{ custom.department }}

Learn more about managing Custom Variables: Custom Variables

Operators & Functions

Learn the syntax you can use to perform math operations and advanced functions using question data, custom data, and custom variables.

Arithmetic Operators

Advanced Piping supports the following basic arithmetic operators:

Operator
Description
Example
Example Description
+Addition{{ Q1 + Q2 }}Sums the values entered into question 1 and question 2
-Subtraction{{ Q1 - Q2 }}Subtracts the value entered into question 1 from the value entered into question 2
*Multiplication{{ Q1 * Q2 }}Multiplies the value entered into question 1 by the value entered into question 2
/Division{{ Q1 / Q2 }}Divides the value entered into question 1 by the value entered into question 2

These operations follow the standard order of operations:

3 + 5 * 12 - 8 / 4 ⇒ 61

However, you can change this by grouping with parentheses:

(3 + 5) * (12 - 8) / 4 ⇒ 8
Comparison Operators

Advanced Piping supports the following comparison operators to compare numbers.

The output of these expressions will always be TRUE or FALSE, and the word "TRUE" or "FALSE" will be inserted into the text of your survey.

Operator
Description
Example
Example Description
=Equals{{ Q1 = Q2 }}The value of Q1 is equal to the value of Q2.
<Less than{{ Q1 < Q2 }}The value of Q1 is less than the value of Q2.
>=Greater than or equal to{{ Q1 >= Q2 }}The value of Q1 is greater than or equal to the value of Q2.
>Greater than{{ Q1 > Q2 }}The value of Q1 is greater than the value of Q2.
Advanced Functions

The following functions are supported by Advanced Piping:

Function
Description
LEN(arg)Returns the length of the array arg.
MIN(args...)Returns the minimum of args, ignoring NULLs, and threading over lists.
MAX(args...)Returns the maximum of args, ignoring NULLs, and threading over lists.
SUM(args...)Returns the sum of args, ignoring NULLs, and threading over lists.
AVG(args...)Returns the average of args, ignoring NULLs, and threading over lists.
STDEV(args...)Returns the sample standard deviation of args, ignoring NULLs, and threading over lists.
STDEVP(args...)Returns the population standard deviation of args, ignoring NULLs, and threading over lists.
IF(cond, true, false)If cond evaluates to TRUE (or a truthy value), evaluates true, else evaluates false.
CONCAT(arg1, arg2...)Concatenates the arguments, threading over lists, and ignoring NULLs. Any remaining arguments will be converted to strings.
COALESCE(arg1, arg2...)Returns the first argument that is not NULL.
INT(arg)Converts arg to an integer by truncating.
BOOL(arg)Converts arg to a boolean value.
REAL(arg)Converts arg to a real number.
STR(arg)Converts arg to a string.
PRECISION(arg, precision)Formats arg as a real number with the given precision.
SUBSTR(string, offset,length)Returns the substring of string at the given offset with the specified length.
TRIM(string)Returns the string with leading and trailing white space removed.
MOD(a, b)Returns the remainder from the division of a by b.
POW(a, b)Returns the value of a to the power of b.
LCM(arg1, arg2...)Returns the least common multiple for the arguments given.
GCD(arg1, arg2...)Returns the greatest common denominator for the arguments given.
STRSPLIT(string, by)Returns a list composed of the elements from string split by by
STRJOIN(by, list)Returns a single string joined together by by from the list list
PART(list, arg)Returns the first index of arg in the given list.
RAND()Returns a random float between 0 and 1.
RANDINT(min, max)Returns a random integer between min and max.
CHOICE(list)Returns a random item from list.
CASE(root_case, args..., default)If root_case evaluates to one of the [0] arguments in pairs from args, returns the evaluated [1] argument of the corresponding pair. Otherwise, returns default.
SGN(arg)Returns the sign of the passed argument. Returns one of -1, 0, 1.
ABS(arg)Returns the absolute value of the number passed to it.
FLOOR(arg)Return the floor of x as a float, the largest integer value less than or equal to arg.
CEIL(arg)Return the ceiling of x as a float, the smallest integer value greater than or equal to arg.
ROUND(arg, ndigits=0)Will return the rounded value of arg to the closest value of 10 (to the power of ndigits). Supports positive and negative ndigits.
LOWER(arg)Returns arg as a string that is completely lowercase.
UPPER(arg)Returns arg as a string that is completely uppercase.
CAPITALIZE(arg)Returns arg with only its first character capitalized and the remaining characters lowercase.
TITLE(arg)Return a title case version of arg where words start with an uppercase character and the remaining characters are lowercase.
  • Enter {{ Q1 + Q2 }} to pipe the sum of the respondent's answers to Q1 and Q2 into the survey.
  • Control the capitalization of any piped text by entering {{ LOWER(Q1) }} or {{ TITLE(contact.custom1) }} so that the output appears in all lowercase, or in title case.
  • Enter {{ AVG(Q1, Q2, Q3) }} to pipe the average of the answers to Q1, Q2, and Q3 into the survey.
This add-on extends the capabilities of Advanced Piping so you can perform math operations and advanced functions with respondent data, and pipe the output into your survey.

Get answers