Control when fields appear based on responses and data conditions
Branching logic allows you to show or hide fields based on participant responses or existing data. It is one of the most powerful tools in REDCap for creating clean, efficient, and dynamic instruments.
On this page
What Branching Logic Does
- Shows fields only when relevant
- Hides unnecessary questions
- Improves data quality
- Creates a guided user experience
How Branching Logic Flows
At its core, branching logic follows a simple decision path: REDCap checks a condition, then either shows or hides the destination field.
[sex] = '0' if Female is coded as 0.How to Set It Up
- Go to Online Designer
- Edit a field
- Enter logic in the Branching Logic box
- Or use the logic builder
Logic Syntax
Basic format:
[variable] = 'value'
Examples:
[gender] = '1' [age] > 18 [consent_complete] = 2 [field_name] <> ""
Simple vs. Complex Branching Logic
Branching logic can range from very simple conditions to more complex, multi-part rules. Understanding how logic builds step-by-step makes it much easier to write and troubleshoot.
Simple Logic
One condition controls whether the field appears.
➡ Show field only if gender = Female
AND Logic
All conditions must be TRUE.
➡ Show field only if BOTH conditions are met
OR Logic
Only one condition must be TRUE.
➡ Show field if ANY condition is met
Complex Logic (Grouped Conditions)
Use parentheses to control how logic is evaluated.
➡ Show field if (q1 OR q2) AND q3 is true
Checkbox Logic Example
Checkboxes require special syntax for each option:
➡ Show field if either checkbox option is selected
Checkbox Logic
Checkboxes use special syntax:
[field(1)] = '1' → checked [field(1)] = '0' → unchecked
Building Complex Logic
([q1] = '1' or [q2] = '1') and [q3] = '2'
Longitudinal Considerations
[baseline_arm_1][weight]
- Reference events explicitly
- Test across events
Limitations
- Cannot hide entire instruments
- Cannot skip surveys
- Works only at field level
Common Mistakes
- ❌ Applying logic to wrong field
- ❌ Treating checkbox like radio
- ❌ Forgetting quotes
- ❌ Not testing with real data
Common Real-World Examples
Branching logic is most useful when it mirrors how people actually move through a form or survey. Below are some common ways it is used in real REDCap projects.
Eligibility Screening
Only show follow-up eligibility questions if the participant meets initial screening criteria.
Use case: Recruitment and screening forms
Sex-Specific Questions
Only display fields when they are relevant to the participant.
Use case: Pregnancy history, prostate-related questions, etc.
“Other, Specify” Fields
Show a text box only when a participant selects “Other.”
Use case: Dropdown or radio fields with an “Other” choice
Medication Lists
Show the next medication field only when the previous one has been completed.
Use case: Repeating-like entry without repeating instruments
Symptom Follow-Up
Show severity or details only if a symptom is present.
Use case: Adverse events, symptom screens, clinical intake
Checkbox-Based Follow-Up
Show additional questions if one or more checkbox options are selected.
Use case: Multi-select symptom or exposure lists
Best Practices
- Keep logic simple
- Use consistent coding
- Test thoroughly
- Use parentheses