Routings and Loops
Go back to the 🔝
- Example 1 : Ask SQ2 only if yes in SQ1 for the L1 loop items 1 &3
- Example 2 : How to check that the sum of the values given to all loop items is equal to 100% ?
- Example 3: Ask Q6 only if yes to all iterations of L4
- Example 4: Routing with loop of loop
- Example 5 : Recode each "yes" in the sub-question into a multi coded
Askia provides an original way of dealing with sub-questions, question tables and level issues : loops.
A loop is a question hierarchy and can be handled with at least:
- 1 loop question (eg L1)
- 1 sub-question (eg SQ1 Do you intend to buy the following brand ? Yes, No)
There are 4 types of loop:
- question table
- loop with selection for each iteration
- loop with preliminary selection
- loop with iteration count entry
The same routing syntax can be used for all loop types.
Example 1
Ask SQ2A only if we have "yes" for the SQ1A and for the L1A loop items "Ariel" and "Ecover"
Depending on the loop layout you have chosen you have 2 options:
A. Chained SQ1A-SQ2A for the same iteration
- L1A is the Question table loop with the following items
- SQ1A is the first sub-question with the items
The routing will be :
| Start question | SQ1A |
| Condition |
L1A.currentiteration has {1;3} and SQ1A.iteration(L1A.currentiteration) has {1} |
|
Action:
|
SQ2A |
The AskiaScript 'CurrentIteration' refers to the current iteration of the loop while 'iteration' refers to a specific iteration of the sub-question.
B. Firstly all items for SQ1B and then only items concerned by the routing for SQ2B
The loop L1B will be a Table question loop with:
- all max visible iterations
and
- the same list of items we have in L1A.
The Loop L1C will be a loop with preliminary selection:
- all max visible iterations
and
- the same list of items we have in L1A.
- linked to the same level as L1B (in order to align result in Analyse for SQ1B and SQ2B)
The routing will be :
| Start question | SQ1B |
| Condition |
L1B.currentiteration has {1;3} and SQ1B.iteration(L1B.currentiteration) has {1} |
|
Action:
|
Value if true*: L1C + L1B.CurrentIteration Value if False**: L1C - L1B.CurrentIteration |
*Value if true : We keep the content of L1C and add the new L1B iteration value
**Value if false : if the respondent go back and change the value , we want to remove the previous value from the L1C values
Example 2 - How to check that the sum of the values given to all loop items is equal to 100% ?
We propose 2 methods.
A/ Set a logic check within the loop
The routing will be :
| Start question | SQ3 |
| Condition |
(L2.IsLastIteration) and SQ3.allvalues.sum() <>100 |
|
Action:
|
B/ Set a logic check outside the loop
We add a chapter 'Sumtest' outside the loop.
The routing will be:
| Start question | Sumtest |
| Condition |
dim sumresult = 0 for i = 1 to L3.responses.count if sumresult <> 100 then |
|
Action:
|
N.B. Whatever the method, we invite you to help the respondent by adding an automatic sum on the screen.
To do it in the example 2A , add a label and insert the following script:
</br></br>
Total remaining % to share :
<b>
!!on(SQ3.allvalues.sum()<>100,
"<span style='color:#DF4335;'>" + (100 - SQ3.allvalues.sum()) + "</span>",
"<span style='color:#00FFC00;'>" + (100 - SQ3.allvalues.sum() )+ "</span>")!!
</b>In the example 2B, add the script in the Sumtest chapter title:
Total remaining % to share :
<b>
!!on(SQ4.allvalues.sum()<>100,
"<span style='color:#DF4335;'>"+ (100 - SQ4.allvalues.sum()) + "</span>",
"<span style='color:#00FFC00;'>" + (100 - SQ4.allvalues.sum() )+ "</span>")!!
</b>
Example 3
I want to ask Q6 only if the respondent answered yes to all items of the loop L4
Add a chapter outside the loop to set the start question routing.
The routing will be :
| Start question | FilQ5 |
| Condition |
dim i dim z = L4.responses.count if SQ5.iteration(i) has {1} then if result = z then
|
|
Action:
|
Example 4
Set a routing on loop of loop
The top loop is L5, the sub-loop is L6.
We want to ask SQ8 when top loop (L5) =place2 (2) and sub-loop (L6) = Ecover (3) and SQ7=Yes (1)
To create the routing, you need first to set the iteration wanted . . .
((L6.currentiteration has{3}) and (L5.currentiteration has {2}))
. . . and follow the syntax "QuestionShorcut . iteration(Sub loop:X, Top Loop:Y)"
(SQ7.iteration(L6.currentiteration, L5.currentiteration) has {1})
The routing will be:
| Start question | SQ7 |
| Condition |
((L6.currentiteration has{3}) and (L5.currentiteration has {2}))
|
|
Action:
|
Example 5
We want to recode into a multi-coded (SQ10), each "yes" in the SQ9 sub-question.
Recode each "yes" in the sub-question into a multi coded
Anytime the respondent said yes (SQ9=1) for an iteration of the loop (L7), we want to recode the iteration into the multi coded question (SQ10).
You can set the recode routing in 2 different ways:
a) After each iteration in the loop
The routing will be :
| Start question | SQ9 |
| Condition |
(SQ9.iteration(L7.currentiteration) has {1})
|
|
Action:
|
Value if true*: SQ10 + L7.CurrentIteration Value if False** : SQ10 - L7.CurrentIteration |
*Value if true : We keep the content of SQ10 and add the new L7 iteration value.
**Value if false : if the respondent go back and change the value , we want to remove the previous value from the SQ10 values.
b) Outside the loop
The routing will be:
| Start question | Recode_SQ10 |
| Condition |
|
|
Action:
|
Value if true:
|
The examples presented in this article are available here 📥 example qex.