Group Logic allows you to randomize questions or sets of questions within a survey. Most commonly used for monadic or sequential monadic survey design, it can also be used to randomize a small number of consecutive questions.
In This Article
- The Basics
- Single Questions
- Question Sets
- Question Numbering Rules
- Max Qualifier
- Advanced Grouping: Balance
- Group Assignment
- Custom Display Order
- Nested Group Logic
- Additional Rules and Behaviors
The Basics
A single logic statement starting with [group...] sets the rules that determine how respondents are directed through the groups in your survey flow.
Group logic can be entered into any question field in the survey. The statement is collected survey-wide, and the group activates as soon as a respondent reaches any question that is a member of the group—not when they reach the question the statement happens to be written in.
💡 Tip: Place the statement in the first question of the group or in a question that precedes it. Placement doesn't change behavior, but it keeps the logic easy to find and maintain
Single Questions
To randomize the order in which respondents see certain consecutively programmed questions, enter this logic into the first question within the group or into a preceding question:
[group Q2 and Q3 and Q4]
When respondents reach any of these questions, they are routed through all three in a varied order. Once they complete all three, they proceed to the next available question.
The order is determined by the assignment method, which defaults to least-fill rather than pure randomization—see Group Assignment. To randomize the order independently for each respondent, add randfill.
Question Sets
To vary the order in which respondents see sets of questions (also called nodes or paths), enter the logic into the first question of the first group, or into any preceding question:
[group Q1-3 and Q4-6 and Q7-9]
Questions within a set (Q1, Q2, Q3) are shown in order, but respondents will start with Q1, Q4, or Q7 in a varied order. Once respondents complete all questions in all three sets, they proceed to the next relevant question.
Question Numbering Rules
Every question number referenced in a single group statement must form one consecutive, gapless block, with no number used twice. This applies across the whole statement, not within each set.
| Statement | Result |
|---|---|
[group Q1 and Q2 and Q3]
|
Valid—Q1–Q3 are consecutive with no gaps or repeats. |
[group Q1-3 and Q4-6 and Q7-9]
|
Valid—Q1–Q9 form one continuous block. |
[group Q1 and Q5 and Q9]
|
Invalid—gaps between the question numbers. |
[group Q1-3 and Q3-5]
|
Invalid—Q3 appears in two sets. |
⚠️ Note: An invalid statement is dropped silently. No error is shown, and the survey fields with no group routing at all. If a group doesn't appear to be working, check the numbering first.
Controlling Order Within a Set
Because the questions in a statement must be consecutive, use dot syntax when you need a set to play in a non-sequential order. Q6.4.5 defines a set containing Q6, Q4, and Q5, shown in that order:
[group Q6.4.5 and Q7.9.8 max 1]
This lets you control order within a set while still satisfying the consecutive-numbering requirement across the statement.
Max Qualifier
If respondents should only see some—not all—of the questions or sets, add a max qualifier. In this example, respondents see only one randomly selected question:
[group Q1 and Q2 and Q3 max 1]
In this example, respondents are assigned to two of the three listed sets:
[group Q1-3 and Q4-6 and Q7-9 max 2]
If all respondents should see all questions in the group, the max qualifier is not needed.
Advanced Grouping: Balance
Add the balance keyword to ensure group assignment is balanced not only at the total level but also within each defined segment, based on prior survey answers and/or demographic traits.
Balance on Demographics
Balance exposure groups based on demographic traits such as gender or age.
Balance by gender:
[Group Q2-4 and Q5-7 and Q8-10 balance gender = "f", gender = "m" max 1]
Balance by age:
[Group Q2-4 and Q5-7 and Q8-10 balance age>=18 and age<=25, age>=26 and age<=41 max 1]
Commas separate balance segments; and joins conditions within a single segment.
⚠️ Note: Balancing on demographics ensures each node is balanced on that trait's distribution within the survey. If you need gender balanced overall across the total sample, apply quotas from the Target Market page.
Balance on Questions and Answers
You can also balance by any questions or answers that precede the groups.
Example: ensure equal distribution for Q5A8, Q5A9, Q4A2 among groups:
[Group Q6-9 and Q10-13 and Q14-17 balance Q5A8, Q5A9, Q4A2]
How Balance Handles Everyone Else
Respondents who match none of the segments you list are not excluded. A residual catch-all segment is created automatically, and those respondents are assigned and balanced among themselves.
💡 Tip: Keep the number of balance segments manageable—40 or fewer, or roughly your sample size divided by 10. Too many segments leaves too few respondents in each one for balancing to be meaningful.
Group Assignment
By default, Group Logic uses the least-fill method—respondents are sent to the group with the fewest completed respondents at that point in fielding, with ties broken at random. This means groups fulfill evenly over the course of fielding. No extra syntax is needed, but you can explicitly add leastfill to the logic if desired.
Least-fill also balances by position, not just total exposure: each set is balanced across each sequential position in the flow. This matters most in sequential monadic designs, where order effects can bias results.
To use purely random assignment instead, add randfill:
[group Q1-3 and Q4-6 and Q7-9 randfill]
When randfill is used, respondents are randomly assigned without regard for how many others have already been assigned to each node. This works well when there's no max limit, but risks uneven fulfillment when a max restriction is in place.
⚠️ Note: Do not use
randfillwith balance—randfill overrides the least-fill assignment that balance relies on to achieve even fulfillment at the total and subgroup level.
⚠️ Note: Before any responses exist, there are no fill counts to compare, so assignment falls back to a random pick. A survey in preview—or in the first moments of fielding—can look more random than it will be across the full sample.
Custom Display Order
By default, Group Logic decides the order in which each respondent sees the paths. To show paths in an order you control, for example the same random order you used to sort a list earlier in the survey, store that order in an array and use a counter to open one path at a time.
This works because of how Group Logic moves through its paths. Each time a respondent finishes a path, the group looks at the paths they haven't seen yet and opens the first one whose question can be shown. Show logic on each path keeps it hidden until its position in the array comes up. A hidden path isn't skipped for good: the group offers it again at the next step.
⚠️ Note: Use this only when respondents see every path. With a max qualifier (or a Smart Loop that shows fewer runs than it has), each respondent sees the first positions of the array, so the array, not the group, decides which paths they get, and the group no longer evens out how often each path is shown.
Set It Up
-
Group the paths. The paths must be listed in a Group Logic command, for example
[group Q5 and Q6 and Q7]. Without Group Logic, the survey only moves forward, so a path that was hidden because it wasn't its turn is never shown. -
Create the order array. Use the values 1 to the number of paths, where 1 is the first path in the group command, 2 the second, and so on. The array lists the paths in the order they should be shown. To randomize it, shuffle it:
[order << 1,2,3][order = shuffle order]. If you already use an array in Sort by logic, you can reuse it. -
Create a counter that starts at 1, for example
[shownext=1]. Put it, together with the array, on a question that every respondent answers before reaching the group. The value is saved when that question is answered, so it can't go on a question inside the group. -
Check the position on every question of each path. Each question shows only when its path is the one at the current position (see the example below). If a question already has show logic, combine the two with
and, keeping the position check in parentheses. -
Raise the counter on the last question of each path that everyone in that path sees:
[shownext+1]. Once it goes up, the position check no longer matches this path. If a question after it in the same path has its own show condition, base that question's logic on an earlier answer in the same path (for example[show if Q6A1]) instead of the position check.
⚠️ Note: If no unseen path can be shown when the group looks for the next one, the group ends and every remaining path is skipped. This happens when the counter isn't raised, or when a respondent doesn't qualify for the path whose turn it is. If a path has its own show logic, leave it out of the array for respondents who don't qualify for it, so their array lists only the paths they can see:
[order << 1][order << 2 if Q1A1][order << 3][order = shuffle order]
Example
Three paths of one question each, Q5, Q6 and Q7. Q4, which every respondent answers, holds the group, the array and the counter:
[group Q5 and Q6 and Q7] [order << 1,2,3][order = shuffle order] [shownext=1]
Q5, the first path:
[show if (order|1=1 and shownext=1) or (order|2=1 and shownext=2) or (order|3=1 and shownext=3)][shownext+1]
| Part | Meaning |
|---|---|
order|1
|
The value at position 1 of the array: the path to show first. |
=1
|
This question belongs to path 1. |
shownext=1
|
Position 1 is the one to show now. |
[shownext+1]
|
Moves the counter to the next position once the question is answered. Q5 is the only question in its path, so it goes here. |
Q6 and Q7 use the same logic, with the path number changed:
[show if (order|1=2 and shownext=1) or (order|2=2 and shownext=2) or (order|3=2 and shownext=3)][shownext+1] [show if (order|1=3 and shownext=1) or (order|2=3 and shownext=2) or (order|3=3 and shownext=3)][shownext+1]
If the shuffled array is 3,1,2, the respondent sees Q7, then Q5, then Q6.
Custom Order in Smart Loops
The same approach works for the runs of a Smart Loop, with two differences:
- Set Assign runs to Evenly or Randomly, and show every run to each respondent. These options add Group Logic to the loop. Static Order adds none, so a run hidden because it wasn't its turn is never shown.
-
Write the logic once, using
[run]. Every run is built from the same loop questions, and[run]becomes each run's number (1 for the first row of the loop table, 2 for the second, and so on). For a loop with three runs:
[show if (order|1=[run] and shownext=1) or (order|2=[run] and shownext=2) or (order|3=[run] and shownext=3)]
Add this to every loop question, and add [shownext+1] to the last loop question only. The array values are run numbers.
💡 Tip: Nested Group Logic in a Smart Loop uses Static Order, because there you write the group logic yourself. A custom display order needs the loop's own group logic, so it uses Evenly or Randomly. Use the Preview tool to check the order before launching.
⚠️ Note: If you use this setup more than once in a survey, create a new counter for each set, or reset the counter (for example
[shownext=1]) before the next set.
Nested Group Logic
Nested Group Logic is advanced aytm Logic that introduces randomization within a larger set of randomized questions—streamlining programming for complex concept testing and reducing bias in respondent data.
Example: [group (q2-3 then q4 and q5) and (q6-q7 then q8 and q9)]
Additional Rules and Behaviors
| Behavior | What to Know |
|---|---|
| Pre-questions can't be grouped | Every reference in a group statement must be a survey question (Q). A statement that references a pre-question (PQ) is rejected. |
| Hidden sets are skipped |
If every question in a set is blocked for a respondent (for example
by [hide] logic), that set is passed over and another
is selected, until the max is reached or no sets remain.
|
| Range size limit | A single range cannot span 100 or more questions. |
| Multiple groups per survey | A survey can contain several independent group statements. Each is evaluated separately, and each must satisfy the numbering rules on its own. |
| No max means no limit | Omitting the max qualifier is equivalent to an unlimited max—respondents see every set in the group. |
| Errors are silent | Invalid statements are discarded without a warning. Always test group routing in preview before fielding. |
Learn more in the Lighthouse Academy course, Group Logic and Smart Loops!