Skip to main content
Loading...
  • Customer Experience
    Customer Experience
  • Employee Experience
    Employee Experience
  • Brand Experience
    Brand Experience
  • Product Experience
    Product Experience
  • Core XM
    Core XM
  • Design XM
    Design XM

Math Operations

What's on This Page:


Was this helpful?


This site is protected by reCAPTCHA and the Google Privacy Policy and Terms of Service apply.

The feedback you submit here is used only to help improve this page.

That’s great! Thank you for your feedback!

Thank you for your feedback!


About Math Operations

Math operations allow you to create custom values with each response. For example, you can create a function that calculates a formula using scoring for individual participants. Math operations can be performed in the survey flow, within a question, or choice text.

Survey Flow

Math operations performed in the survey flow should be saved as embedded data. The results of the equation are not displayed to the respondent by default. If you would like to display the results of the equation to respondents, you can do so through the use of piped text.

Math operations shown as Weighted Satisfaction embedded data in the Survey flow

In this survey, the answers to two questions are summed, multiplied by 1.33, and saved as an embedded data field called Weighted Satisfaction.

Question or Choice Text

Math operations performed in question or choice text are displayed to the respondent, but are not reported in the survey results.

Displaying math operations in the survey editor

In this survey, the results of a math operation will be displayed as part of the text in a survey question.

Math Operations Syntax

All math operations are contained within the following syntax:

$e{ }

The math equation will be inserted between { and }. All items in the equation should be separated by a space.

$e{ 4 + 4 }

Syntax in Right-to-Left Languages

If your survey is written in a right-to-left language such as Hebrew or Arabic, the syntax you use for math operations is a little different:

{ }#$

Example: To add 4 + 4:

{ 4 + 4 }#$

The math equation will be inserted between { and }. All items in the equation should be separated by a space.

Using Piped Text

Adding 4 + 4 is great, but more useful is the ability to perform math operations on answers provided in the survey. For example, one study may call for multiplying the answer to a satisfaction question by a fixed number. This is where piped text comes in.

Piped text is used to pull in a dynamic number for each respondent. For a review on how to generate the piped text code representing the number needed in your equation, refer to our piped text support page.

Piped text follows a specific format:

${q://QID1/SelectedChoicesRecode}

To use piped text in a math operation, remove the ${ and }. The resulting code would look like this:

q://QID1/SelectedChoicesRecode

Once placed in a math operation, the operation would look like this:

$e{ q://QID1/SelectedChoicesRecode * 4 }

Decimals & Thousands Separators

  • Math operations support numeric values only.
  • In computer science the decimal is defined as a period (.) separator. You will not be able to use a comma (,) as a decimal.
    Example: $e{ 1.5 + 1 } will equal 2.5, which is correct. $e{ 1,5 + 1 } will equal 1, which is incorrect.
  • Thousands separators or decimal commas (,) can break the math operation. Instead, omit the thousand separator or decimal commas.
    Example: When trying to work with a number in the thousands, $e{ 1000 + 1 } will equal 1001, which is correct. $e{ 1,000 + 1 } will equal 1, which is incorrect in this example. $e{ 1.000 + 1 } will equal 2, which is also incorrect in this example.

Available Operations

Addition, Subtraction, Multiplication, and Division

$e{ 1 + 2 - 3 / 4 * 8 } resolves to -3.
Qtip: For an easy way to perform simple addition, consider using the Scoring feature instead of math operations.

Parentheses

Parentheses may be added to specify order of operations.

$e{ ( 1 + 2 - 3 ) / 4 * 8 } resolves to 0.
Qtip: Math operations follow the standard order of operations: Parentheses, Exponents, Multiplication, Division, Addition, Subtraction.

Exponents

$e{ 6 ^ 2 } resolves to 36.

Square Roots

$e{ sqrt( 9 ) } resolves to 3.

Using an exponent instead would also be appropriate. For example, $e{ 9 ^ ( 1 / 2 ) }.

Absolute Value

$e{ abs( -23 ) } resolves to 23.

Rounding

$e{ round( 10 / 3 , 2 ) } rounds 10/3 with 2 decimal places and resolves to 3.33.

Remainder

$e{ 16 % 9 } divides 16 by 9 and returns the remainder, which is 7.

 

Troubleshooting Math Operations

Math operations may not evaluate if they are formatted incorrectly. If your math operation is not evaluating, check for two common errors: HTML spaces in the equation and incorrectly formatted piped text.

HTML Spaces

When writing a math equation in the rich content editor, spaces may be converted into HTML, invalidating the equation. The following equation looks fine in the standard view of the rich content editor:

Accessing the rich content editor from the survey editor

However, switching to the source view of the text editor, you will notice one of the spaces has been converted to HTML, displayed as “ ”.

Source view in the rich content editor showing the extra   in the code

  and other HTML tags invalidate a math equation. Remove these from the source view to fix the equation.

Incorrectly Formatted Piped Text

As discussed above, when using piped text in a math operation, $ and {  } should be removed from the piped text code. For instance, the piped text code ${q://QID1/SelectedChoicesRecode} should be used in a math equation as q://QID1/SelectedChoicesRecode.

Many math operations will work fine if $ and {  } are not removed from the piped text. However, if the piped text does not have a value (for example, if the respondent skipped the question the piped text is referencing) and if $ and {  } have not been removed, the equation will fail.

Remove $ and {  } from all equations to prevent failures when the piped text is empty.

See the Math Operations Syntax section above to ensure you are following all syntax rules in your math operations.

Incorrect Spacing in the Equation

Remember, every item in your math equation needs to be separated by a space. If you’re having trouble finding the spaces in your equation, follow the below steps:

  1. Copy your equation.
  2. Open a text editor, such as Microsoft Word.
  3. Perform a search. On Mac, this is CMD + F and on PC, this is CTRL + F.
  4. Search for a space by pressing the space bar on your keyboard.
  5. All of the spaces in your formula should be highlighted. You can then identify where you are missing spaces.
Example: In this example, we pasted an equation into Microsoft Word and searched for the space character. We can see all of the spaces in the equation are highlighted in the document, and that this equation has correct spacing.a math equation has been pasted into a word document. a search was performed for the space character, so each space in the equation is highlighted.