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 across different lists.
Tip! List functions can reference any list type. For derived lists referencing a table, use a leading 'T'.
Additional examples
Used in a condition decorator
In this example, Q6 is asked for products with a total quantity of two or more at Q5, regardless of brand. listSum
adds across all brands to find these products.
Since the PRODUCTS list is iterated at rowsfrom
using [id]
, the other list in listSum
must be specified by prefixing its name to the the [id]
placeholder.
setlist: PRODUCTS
1. PCs
2. Servers
3. Mobile devices
setlist: BRANDS2
1. Lenovo
2. Apple
3. Dell
4. Toshiba
5. HP
6. Samsung
5. How many of each product do you have with each brand?
type: integer table
size: 3
rowsfrom: BRANDS2
colsfrom: PRODUCTS
6. You mentioned you have at least two products for each of the following devices. Why do you have redundancy for each?
type: textbox table
rowsfrom: PRODUCTS {if listSum(BRANDS2; $Q5R[BRANDS2:id]C[id]) > 1}
Summing all options from multiple lists
In this example, listSum
uses two lists to calculate the cvalue
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.
setlist: PRODS
1. Desktop Computers
2. Laptop Computers
3. Mobile Devices
4. What products have you purchased from each manufacturer?
type: pulldown table
colsfrom: PRODS
optsfrom: series[0..10]
rows:
1. Lenovo
2. Apple
3. Dell
4. Toshiba
5. HP
6. Samsung
97. Other { autoother: y; placeholder: Please specify }
TOTAL. Total products purchased
type: coded number
cvalue: listSum(T4.rows, PRODS; $Q4R[T4.rows:id]C[PRODS:id] )
Comments
0 comments
Please sign in to leave a comment.