The listSum
function iterates through a list and sums the referenced survey fields.
setlist: BRANDS
1. Amazon
2. Alibaba
3. Etsy
1. How many purchases have you made from each of the following websites in the past month?
type: radio table
rowsfrom: BRANDS
optsfrom: series[0..10]
1TOTAL. Total number of purchases
type: coded number
cvalue: listSum(BRANDS; $Q1R[id])
Tip! Not sure which list function is best suited for your needs? Review all list functions here.
Details
-
In its most basic form,
listSum
accepts two inputs: a list name and a field reference constructed with the '[id]' placeholder. - Options can be filtered in or out of the list with inclusion/exclusion syntax.
-
listSum
can be used withcvalue
, as shown above, as well as in conditional statements withshowif
andcondition
, (e.g.,showif: listSum(T2.rows-[97]; $Q2R[id]) >= 20)
. - When multiple lists or conditions are used, the list name is prefixed to the
[id]
reference and separated by a colon, (e.g.,[LISTNAME:id]
). Prefixing clarifies list references and is necessary for the software to iterate and sum calculations across different lists.
Additional examples
Used in a condition decorator
In this example, respondents are asked follow-up question Q6 for any of the products they have two or more of at Q5, regardless of brand. The listSum
is adding across all of the brands, looking for the products that have two or more as a total quantity.
Since the PRODUCTS list referenced at rowsfrom
will be iterated through the [id]
reference in the logical statement, the other list iterated through the listSum
function needs to be clarified further. Again, the list name will be prefixed to the the [id]
placeholder.
Summing all options from multiple lists
In the next example, we use two lists in the listSum
function to calculate the answer for the cvalue
tag at QTOTAL. One list is a derived list from Q4, and the other is the standalone list PRODS. Each list name is prefixed to the [id]
reference where the list will be iterated through (the rows and columns [id]
placeholders) and separated by a colon.
Comments
0 comments
Please sign in to leave a comment.