The sortfor
tag is valid on text widgets, and is used to sort and reorder list elements. It accepts a list or sheet name, and a weight
element decorator. The contents of the weight
decorator are evaluated for each list element. sortfor
then generates a sequential order string, sorted by the contents of the weight
decorators. Finally, sortfor
populates the parent text widget with that string.
Tip! If the returned order string does not have the same number of elements as the input list. The remaining elements are placed at the end of the list to prevent missing elements.
Syntax
VAR. A text variable type: text sortfor: LISTNAME {weight: Expression to evaluate}
Examples
Sort text values from a block, use for question option ordering
In this example, the sortfor
tag at QC_BRAND_ORD uses the number of purchases entered at Q1 for each brand to determine the sorting weight. That order is then used for the Q2 option order.
Sort values from a 100% table, use for block ordering
This example uses the percentage entered for each brand at Q3 to determine the sortfor
weight. The QF_BRAND_ORD variable is then applied to the block to determine the order the NPS questions are displayed.
Sort values from an awareness table, Brand 1 always first
In this example, the expression (([id]==1)*100)
gives Brand 1 a weight of 100, to ensure that sortfor
always sorts it first. The other brands use the option selected at Q5 as the weight, which has 3 as the highest value.
Ranking, opposite sort
Note: sortfor
with ranking questions requires special consideration — please read the following carefully.
Using sortfor
with ranking questions is slightly counterintuitive, because ranking typically uses '1' as the highest value, while sortfor
considers '1' the lowest value. The result is that sortfor
's output would be the reverse of what is typically desired. We can account for this by making the weight negative, because sortfor
will sort -1 first, then -2, -3, etc.
In this example, the expression in the weight
decorator is saying: "If $Q7R[id]
has a value, make it negative; otherwise, set it to -99,999." The -99,999 value is an arbitrarily large negative number to ensure that unranked options are always sorted last.
Sort based on weight
You can also use sortfor
to establish a sequential order based on the weight assigned to a list of options. For instance, the QORD_Q12 variable evaluates each item in the BRANDS list, assigning the highest weight to the option selected as the "go to" brand at Q11, followed by the options selected at Q10, followed by all remaining items in the BRANDS list. The order is then applied to Q12 with the flatorder
tag.
Comments
0 comments
Please sign in to leave a comment.