Customizing the Respondent Path with LimeSurvey Conditions.
Objective
- Understand how conditional filter equations (Relevance Equation) work.
- Create conditions to show or hide questions based on previous responses.
- Combine multiple conditions using AND and OR logical operators.
Why use conditional filter equations?
- To shorten the survey by hiding irrelevant questions.
- To improve the respondent experience with a personalized path.
- To collect more accurate data by asking only appropriate questions.
1. Accessing the Relevance Equation field
The relevance equation determines whether a question or group is displayed. It must always return TRUE (display) or FALSE (hide).
- Open the settings of the target question or target group you want to condition.
- Look for the "Relevance Equation" field.
- Enter your formula in this field.
Note: Do not use the visual condition designer for these advanced formulas. Work directly in the Relevance Equation field.
2. Essential terminology
Before creating your conditions, familiarize yourself with these terms:
- Source question: the question whose response triggers the condition (e.g.,
Q1). - Target question: the question that appears or disappears based on the condition.
- Response code: the technical identifier of a response option (e.g.,
Y,N,A1).
3. Conditioning on a single response
This case applies to multiple choice, yes/no, or dropdown list questions.
Display if the user chooses YES
Q1 == "Y"Translation: Is the response to Q1 equal to Y?
Display if the user chooses NO
Q1 != "Y"Translation: Is the response to Q1 different from Y?
Display if the user chooses a specific option
Q1 == "C3"Translation: Is Q1 equal to response code C3?
Tip: To find the code of a response option, check the source question settings in LimeSurvey.
4. Conditioning on text field completion
Use this method for short or long text fields to check whether the respondent has entered something.
The is_empty() function
This function checks whether a field is empty or not.
Display if the user has written something
!is_empty(Q3)Translation: The content of Q3 is not empty.
Display if the user has left the field empty
is_empty(Q3)Translation: The content of Q3 is empty.
Note: The exclamation mark
!means NOT (negation). It reverses the result of the function.
5. Conditioning on option ranking
For ranking type questions, you can check whether an option has been ranked, regardless of its position.
Check if an option has received a rank
!is_empty(Q4_A05)Translation: The rank assigned to option A05 is not empty (the option has been ranked).
Advanced explanation:
Q4is the code of the ranking question.A05is the code of the specific option.- The syntax
Q4_A05allows access to the rank assigned to this option.
6. Combining conditions with logical operators
You can create complex conditions by combining multiple expressions.
AND operator
Both conditions must be TRUE for the target to be displayed.
(Q1 == "Y") AND !is_empty(Q3)Translation: Q1 is YES AND Q3 is not empty.
OR operator
At least one of the conditions must be TRUE for the target to be displayed.
(Q1 == "Y") OR (Q2 == "Y")Translation: Q1 is YES OR Q2 is YES.
Tip: Always use parentheses to group your conditions. This ensures that LimeSurvey interprets the logic in the correct order.
7. Complex condition example
Here is an example combining multiple operators for advanced logic.
Objective
Display the target question if the user answered YES to Q1 AND left field Q3 empty, OR if they chose option B for Q2.
Formula
( (Q1 == "Y") AND is_empty(Q3) ) OR (Q2 == "B")
Logic breakdown
- First part:
(Q1 == "Y") AND is_empty(Q3)checks if Q1 is YES and Q3 is empty. - Second part:
(Q2 == "B")checks if Q2 equals B. - Result: The target is displayed if the first part OR the second part is true.
8. Best practices
- Test your conditions by previewing the survey before publication.
- Document your formulas in an external file for easier maintenance.
- Use explicit question codes (e.g.,
satisfactionrather thanQ1) to improve readability. - Check response codes in each question's settings before using them.
9. Troubleshooting
The condition does not work as expected
Solution: Verify that the source question code and response codes exactly match those defined in LimeSurvey. Codes are case-sensitive.
The target question always remains hidden
Solution: Ensure that the source question is placed before the target question in the survey order. A condition can only reference a question that has already been asked.
Syntax error in the formula
Solution: Check that you are using double quotes for strings and that all parentheses are correctly closed.
Need help?
For any difficulty, contact the LimeSurvey team via: Cellule.Web@ulb.be