Overview
In this tutorial, we'll discuss creating selection logic using the selectby
tag. The selectby
tag is used on closed-ended questions to automatically assign a value to the question where the tag is placed based on the selection method, such as counts or weights. The selectby
tag considers logic from element decorators or other tags to determine the final value.
Variables with the selectby
tag are hidden from respondents and are automatically processed by the system when the page is submitted.
These hidden selection variables are often used to fulfill various survey instructions, such as deriving data from previous answers to use in later logic, prioritizing brands, or providing specific data for reporting requirements. There are many reasons for using selectby
to create hidden questions, and this tutorial provides some common examples.
Related reading and resources
The following articles can be used for reference with this training module:
Survey Variables video
The following video demonstrates how to create a hidden variable using the selectby
tag or with a coded variable. Additionally, it provides an overview of the three most common selection methods: condition, counts, and weight. We recommend watching this video before continuing with the tutorial.
Using selectby
Open the 'Tutorial - selection logic.docx' document (linked below) and review the selection-related questionnaire instructions highlighted in pink/fuchsia. We will add the code covered below to your FLast_r8_intro survey's existing content.
Questionnaire Content | Discussion Details | Coded SPL |
[Select one based on most needed of the colors selected at A2] |
The first instruction is a standard selection based on respondent awareness. When a selection is asking for "most needed," this means the option with the lowest number of completes. This is sometimes referred to as the "least filled." The AWARE variable is single select, and will pick one color from the options selected at A2. The 'counts' parameter tells the software to look at the current completes to find out which one has the lowest number, and then that option is selected for the respondent. Note: |
Place this code after A2:
AWARE. A2 Awareness type: radio selectby: counts optsfrom: QA2 |
[Classify 2 most common shapes, options 1 or 2 at B1A] |
In the next instruction for B1A, we need a variable to select the shapes that have either of the ratings '1' or '2' selected. The SHAPE variable needs to be multi-select ( Lastly, the 'counts' value is used to select the options with the lowest numbers of completes. |
Place this code after B1A:
SHAPE. Common Shapes type: checkbox maxgroups: 2 selectby: counts optsfrom: SHAPES {if anyChecked($QB1AR[id],1,2)} |
[Classify all with 5 or more encounters per day, options 5 or 6 at B1B] |
The variable TOP is also a checkbox selection. We want to include all of the shapes encountered five or more times a day. Using The second example is using |
Place this code after B1B:
TOP. Most Shape Encounters type: checkbox selectby: condition optsfrom: SHAPES {if anyChecked($QB1BR[id],5,6)}Or you can use this code: TOP. Most Shape Encounters type: coded multi select optsfrom: SHAPES {if anyChecked($QB1BR[id],5,6)} |
B5C2. Why do you have the most space for a [Insert shape with the largest percent from B5C]? [Single select; randomize; anchor other] |
For the last example, we'll need a hidden question (variable) to determine the shape with the largest percentage assigned from B5C. Then, we'll use this information to insert text into the new question B5C2. To accomplish this, we'll use The variable B5CLG checks each row from B5C to identify the shape with the highest percentage. It iterates through each In the event of a tie, the second parameter in place can perform another evaluation and make the final selection. In this case, if there is a tie, we will ask the client if we can choose the shape with the least number of completes by using 'counts'. Then, the hidden variable's selection can be piped into question text. Tip! Wrapping the question pipe with Lastly, use the |
Place this code after B5C:
B5CLG. Largest Allocation type: radio selectby: weight, counts optsfrom: SHAPES {if $QB5CR[id]>0} {weight: $QB5CR[id]} B5C2. Why do you have the most space for a <b>[* lc($QB5CLG_text) *]</b>? type: radio randomize: y 1. Convenient shape in the space 2. Is helpful for random tasks 3. Helps me define borders 4. Offers me the best price 97. Other (specify) {autoother: y} {anchor: y} |
Practice what you've learned
Continue to work in your FLast_r8_intro survey (visit Training tutorials for set up steps) by integrating the new content from above.
Once you finish reviewing each survey question, add the new content to your survey area via the Survey Editor. When the survey compiles successfully, launch Testmode by clicking the Test 2 button from this screen. As you move through your survey, use the New Values field in bottom portion of the Testmode toolbar to see the value(s) stored at each variable, based on your answers.
Reminder, once you integrate all the new content from this tutorial and test it, publish your survey before moving on to the next tutorial.
Previous/Next
Skip logic tutorial/Create quotas tutorial
Comments
0 comments
Please sign in to leave a comment.