Using Advanced Expression Piping within your forms you can create mathematical formulas in order to calculate a value. The most common formula that can be used is the SUM function. This article will demonstrate how to configure a SUM expression using AEP within a form.
In this Article...
The SUM function will sum a list of values from a number of given fields and is the most commonly used function within expression piping. A SUM function can be created by listing the identifiers of the questions you want to add together.
The setup and formatting of the SUM expression are imperative in preventing an error message from appearing on your form where the sum of your expression would normally appear. The first line of the SUM expression should be set up as follows:
{{ SUM(variable1,variable2) }} |
- Each expression is always contained within a pair of double braces {{ }}
- There should be a space between the first instance of SUM and the last bracket
- Variables you are using are case sensitive for the spelling of the Identifier
- Always close each SUM operation with brackets ( )
In addition to listing the values in specific text response cells and questions, you can also pull a SUM of Columns, Rows, and Ranges from Single- and Multi-Column questions, as well as Scores from closed-ended questions.
Sum of a Column | {{ SUM(q1[:0]) }} |
Based on Grid Indexing, this will find the sum of column 1. |
Sum of a Row | {{ SUM(q2[1:]) }} |
Based on Grid Indexing, this will find the sum of Row 2. |
Sum of a Range | {{ SUM(q1[0:4]) }} |
Based on Grid Indexing, this will give you the sum of the first 4 cells. |
Sum of Scores | {{ SUM(q1.score,q2.score,q3.score) }} |
The score given to each of the 3 questions will be added to the sum. NOTE: In this example, three questions have been given identifiers of q1, q2, and q3. These questions exist within the same form. |
TIP! Remember that the first row in a table is referred to as row 0 as it generally holds column headers. Looking at the sum of a row example above, if we were looking to calculate row 3, the expression would appear as {{ SUM(q2[2:]) }}.
{{ SUM(Q1[:0]) }} |
{{ SUM(Q1[0:]) }} |
{{ SUM(Q1[0:5]) }} |