The listWhich
function iterates over a list and returns either the first iteration that evaluates to true, or optionally all iterations that evaluate to true. The values returned can be an ID, text, or other list related data.
5. What is your experience with the following brands?
type: radio table
1. Never used
2. Used, but not in the past 12 months
3. Used 6 - 12 months ago
4. Used within the past 6 months
rows:
1. BRAND A
2. BRAND B
3. BRAND C
4. BRAND D
5. BRAND E
set value
question: { "Q6R" . listWhich(T5.rows; $Q5R[id]==4; [id]) }
value: 100
condition: listCount(T5.rows; $Q5R[id]==4) == 1
6. What percent of your spending has been for products from each of the following brands in the past 6 months?
showif: listCount(T5.rows; $Q5R[id]==4) > 1
type: integer table
postfix: %
size: 3
datatype: whole
rowsfrom: T5.rows {if anyChecked($Q5R[id],4)}
sct: y {total: 100}
Tip! Not sure which list function is best suited for your needs? Review all list functions here.
Details
-
listWhich
accepts three inputs: a list name, and a field reference constructed with the '[id]' placeholder, and a data element reference, also constructed with the '[id]' placeholder. - Options can be filtered in or out of the list with inclusion/exclusion syntax.
- 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. - Additionally, [ square brackets ] may be placed around a
listWhich
function in order to return all items in a comma-separated string, rather than just one, (e.g.,cvalue: [listWhich(LIST1,LIST2;anyChecked($Q10R[LIST1:id],[LIST2:id]);[LIST2:id])]
). - If no square brackets are used,
listWhich
returns only one value. - The
listWhich
tag works best with theset value
,cvalue
, anddvalue
tags. - As currently designed,
listWhich
is not intended for use with conditional decorators.
Additional examples
Using multiple lists
In this example, respondents rank suppliers on a 10-point scale across different material types which are presented in a block. The material-supplier combinations ranked 8 or higher are then coded into a closed-ended variable, QRATED8, using the crosslist TYPES_BY_SUPPLIERS. We use two lists in listWhich
to check each iteration of the Q8_%%ID%%
block, replacing the %%ID%%
with the TYPES list IDs, and replacing each table row with the SUPPLIERS list IDs. Each list name is prefixed to the [id]
reference where the list will be iterated through and separated by a colon.
Since block iterations often return multiple responses rated 8 or higher, square brackets are used around the listWhich
function to return all matching responses. Finally each matching response will return the IDs needed to "punch" the variable with the correct TYPES_BY_SUPPLERS ID.
Please scroll to see the full code.
Comments
0 comments
Please sign in to leave a comment.