Setting conditions
Overview of conditions in LimeSurvey
A condition decides whether participants see a question. A question with a condition appears only when its condition is true, for example a follow-up question that only laptop users get. Otherwise LimeSurvey skips it.
To add a condition, select the question. The Condition designer is at the end of Question settings. See Set conditions.
LimeSurvey saves the conditions of a question as an expression, the Condition of the question. You can also write or edit this expression yourself. Question groups have a condition of their own, see Show a question group only sometimes.
To try the examples yourself, download the condition sample survey: LimeSurvey_Survey_Setting_Conditions.zip.
Hide/show branching versus jump branching
You can design logical branching with LimeSurvey: some questions are displayed only if some conditions are met, like "Show question X if the answer to question Y was Z".
Our approach is to implement a Hide/Show Branching Logic:
- you can define a condition or a set of conditions on each question of your survey - if the condition is met, the question will be then displayed.
- a question without a condition defined on it will always be displayed;
- a question with a condition defined on it will not be displayed unless the condition is met.
This approach is different from the Jump Branching Logic that is sometimes implemented by other software. In the Jump Branching Logic, the resulting action of a met condition would be to jump to another question (that is to say hide all questions in between). LimeSurvey doesn't implement this Jump Branching Logic method. Instead, if you wish to jump a series of questions, you should simply set the same condition on all the questions you do not wish to be displayed. For example, if the jump condition you want to set on Question2 is "Jump to Question5 if the answer to Question1 is 'Yes'", you can simply:
- set a condition on questions 2, 3 and 4 to only display "if the answer to Question1 was NOT 'Yes'"
You don't have to build the same condition several times. Copy the expression of the condition and paste it into the expression field of the other questions, see Edit or remove a condition.
Supported types of conditions
Basically, a condition can compare values, returning either true or false.
The values that can be compared are answers to previous questions. For instance, if you answer 'Yes' to Question1, Question2 will then be shown to the survey respondent.
At this point, it is important to understand what is considered an eligible question-entry for the condition editor.
A question-entry is either:
- a simple question (for all question types apart from Array questions)
- for instance: text questions, radio or dropdown lists, and even multiple choices questions
- or a row in Array questions (except for Array dual scale and Array multiple flexible questions)
- for instance: array with 5 radio buttons or array with label questions
- or either the left part or the right part of an Array dual scale question
- or each cell of an Array flexible question
- constant values
- for instance: "If you answered more than 18 years to the question below"
- Participants' profile data: To use data from the participant list, Anonymized responses must be set to Off. You find this option in the participant settings of the survey.
Several comparison operators are supported - from the simple "equals" to the advanced "regular expression":
- The basic ones refer to the "equal" and "not equal to" operations
- The greater/less than operator family is also available, and is usually used when using numeric question-entries
- Please note that comparisons on numeric fields make use of the numeric order. For instance, 2 < 10
- If you're using a question entry whose type is text, the condition could be evaluated as "2" > "10" (string order)!
- Numeric questions, as well as text questions (when they have the 'numbers_only' attribute set), will use the numeric order for comparisons
- An advanced comparison operator using regular expressions is also available (don't panic! If you don't know what this means, then you don't need it)
- you don't need to enclose the pattern in '/' characters
- for instance: [a-zA-Z]$
Set conditions
Add a condition to a question
- Select the question that should appear only sometimes.
- In Question settings, under Condition designer, click + New logic. The designer opens in the panel.
- Under Display only if, leave Question selected to use an earlier answer. Participant data uses a field of the participant list instead.
- Choose the earlier question in Previous questions (1). Only questions that come before this one are listed.
- Choose the comparison (2): equals, Not equal to, Less than, Less than or equal to, Greater than, Greater than or equal to or Regular expression.
- Under Reference value (3), choose what to compare with, then the value. Select answer option(s) lists the answer options of the earlier question: pick one or more. The other choices are Free value (constant), Compare to answer of other question and Participant data, and RegExp for the comparison Regular expression.
- Click + Add condition (4) for another condition, or Apply (5).

LimeSurvey confirms with Condition applied successfully. The question gets a C badge in the editor (1), and the condition is listed as Scenario 1 with its expression (2), here ((Q001.NAOK == "A002")): show the question when the answer to Q001 has the code A002. Click the C badge to jump to the Condition designer of the question.

Combine conditions
- Several answer options in one condition: the question shows when any of them was chosen.
- Several conditions in one scenario: build them with + Add condition. A question with conditions on different earlier questions shows only when all of them are true.
- Several scenarios: the question shows when any scenario is true. To add one, click + New logic again and change Default scenario from
1to2. The expression then joins the scenarios withor.
Edit or remove a condition
- To change a scenario, click its name, for example Scenario 1.
- To remove a scenario, click the x next to it and confirm with Delete.
- To remove all conditions of the question, click the x next to the expression and confirm with Delete.
- To write or edit the expression yourself, click the expression field (Enter expression... when the question has no condition) or the square icon next to it. The ExpressionScript editor opens. Click Apply to save.
Show a question group only sometimes
A question group has a condition of its own. When it is false, LimeSurvey skips the whole group. Click the group in the Structure panel. In Group settings, type an expression into Condition, for example Q001 == "A002".
1 or an empty field means that the group is always shown. See also ExpressionScript Engine - Quick start guide.
A002 is the code of the answer "Laptop". Click ... ⇒ View ⇒ Question codes in the top bar to see the codes. Test your conditions with Preview survey (the eye icon in the top bar) before you activate the survey.Things to watch out for
General considerations
There are a few basic rules you should keep in mind before setting conditions on a question:
- Once a single condition has been set for a question, that question will not be displayed unless that condition is met.
- Conditions can only be set based on questions that appear before the question on which the condition is set.
- If you change the order of questions in your survey after you create conditions, LimeSurvey does not warn you if the changed order will break any of your conditions. You should always put aside the creation of conditions until you are satisfied with the order of questions and groups in your survey.
- You can modify conditions even after a survey has been activated. This should be done with caution, as there is no "consistency checking" applied here.
Chained conditions
If you set conditions on a question that, itself, has conditions, you could end up with your survey behaving in ways you might not have predicted. For example, a typical side-effect is that if you hide all questions in a group with chained conditions, the group header will still be shown unless you correct these conditions as explained below.
For example, the 'Alcohol' question is displayed if the respondent has previously answered to the 'AAMN' question 'No (N)'. However, the 'AAMN' question might not be displayed at the end if the respondent did not select to the previous question ('Gender') answer 'Male (M)'. In this scenario, no 'Alcohol' question will be displayed if 'Male (M)' was not chosen previously.
To have the 'Alcohol' question displayed, you have to copy the conditions from the earlier question(s) to the one you're editing. To have the 'Alcohol' question displayed, you need to set up the following set of conditions:
- Show 'AAMN' if the answer to 'Gender' is 'Male (M)'
- Show 'Alcohol' if answer to 'Gender' is 'Male (M)' and if answer to 'AAMN' is No (N)'.
So if you are designing a complicated survey with a large number of conditions, make sure you test the survey for as many different combinations of results as you can think of.
Limitations and workarounds
Progress-bar
If you create a survey where many questions get skipped because of conditions, the progress bar either jumps over a set of questions or the survey ends at 50%.
To avoid such behavior, the questions that could be skipped should be arranged between the shown questions. In this way, only one or two questions get skipped per answer.
For example, based on Question1 (yes or no question), 14 questions (2A to 15A) will be displayed if the answer to Question1 is 'Yes', or 2B to 15B if the answer to Question1 was 'No'.
If you arrange the questions in one group and arrange them like 2A, 2B, 3A, 3B, and so on, you will get a nearly correct progress bar, while arranging the questions like 2A, 3A, 4A, [...], 2B, 3B, 4B, ... you will get a progress bar from 0 to 50% or from 50% to 100%, depending on the answer to the first question.
Setting a constant comparison value for a "Date" question type
You have to use the internal representation of Date values (which is YYYY-MM-DD) to define your constant comparison value.
Setting conditions for "Other" options in the multiple choice question type
In the multiple choice question type, participants can tick "Other" and type a text. You can't set a condition on the "Other" checkbox itself, but you can test whether the participant typed something into the "Other" text field.
Write the expression yourself in the expression field, for example !is_empty(MultipleOrganization_other).
If you need a condition on a real "Other" checkbox, add an explicit answer option called 'Other' and do not use the built-in 'other' option of these question types. Then add an additional short text question which will be displayed if this 'Other' checkbox was clicked.
How to use parentheses for the boolean expressions?
Not with the condition designer. Write the expression yourself in the ExpressionScript editor instead. For example: (Q1 == "A1" or Q2 == "A1") and (Q3 == "A1" or Q4 == "A1").
With the condition designer, if you want to design something like:
(condition1 OR condition2) AND (condition3 OR condition4),
you'll have to set up:
(condition1 AND condition3) OR
(condition1 AND condition4) OR
(condition2 AND condition3) OR
(condition2 AND condition4)
FAQ
Why is a question missing from Previous questions?
A condition can only use questions that come earlier in the survey. Move the question you want to use above the one that gets the condition.
The question with a condition still shows in the preview. Why?
Check the answer code in the condition against the answer you gave in the preview. Turn on ... ⇒ View ⇒ Question codes to see the code of each answer option next to it.