Click on the magnifying glass to the right. Starting typing a topic you wish to learn about
REDCap 101.5: Branching Logic
Branching Logic Basics
Branching logic allows you to keep a field hidden until needed. For instance, if a question pertains to one type of participant, but not another, the field will remain hidden to the participants that don’t need to see it, and appear for those that do need to see it.
Branching logic is:
always based on previous logic
can only be coded within a project, not between multiple projects
available between instruments within a project
can be developed by two methods; beginner-friendly drag and drop method or advanced syntax method for use cases not possible with drag and drop.
Example of branching logic development
Develop a field that is only required for certain participants such as the following:
Define your parameters for that field such as [age] > 18 (age is greater than 18). You can find your field names and variable designations by going to the Codebook located near “Designer” and “Dictionary” on the left side of the screen.
Click the branching logic icon on the field that is only required for certain participants. Here you can drag and drop (easiest method) or use advanced syntax and hand type your logic in the box above. as seen below:
Drag and drop format
Decide which instrument your logic is coming from for that field
Drag and drop the field choice for your logic. Here we dragged “[age]” it then allows you to complete your criteria, such as greater than or equal to and add a number. We chose greater than 18. This means that if a participant selects an age below 18, then the field we are editing the branching logic for, will be not be visible. If they select and age above 18, then this field will be visible. This is the same for surveys or data entry forms.
When your participant or study team is completing either the survey or data entry form, they will only see that field when the [age] > 18 from a previously completed field. In this example the “age” is selected in the same instrument as the new field, however you can use branching logic across instruments just not across projects.
Here is an example of how to use branching logic across instruments:
I am in the Medication instrument, however I want to base a Medication question off an answer to a Demographics question. You can select the drop down box above your Field Choices and select the instrument you want to define your logic from. Remember: it has to be based on a answer that comes before the field you are setting up branching logic for.
Remember:
If there is no branching logic for a field, that field will always present itself to every participant.
If you rename the variable for a field, remember to change the branching logic that is associated with variable name. For instance if you change [gender] to [gender_one], you will need to go to the field that has branching logic [gender]='1' and change the branching logic to [gender_one]='1'.
Always test your project thoroughly to ensure your branching logic is working as expected.
REDCap Branching Logic Language using Advanced Syntax
And statements use the logic “and” between parameters. Use this logic if you need your branching logic to fire based on two parameters such as [age] > 18 and [sex] = '1' (Here we are saying “age greater than 18 and sex is equal to 1 which will either be Male or Female depending on your field choices).
Or statements use the logic “or” between parameters. Use this logic if your branching logic can fire based on one or the other parameters such as [age] > 18 or [sex] = '1' (Here we are saying “age greater than 18 or sex is equal to 1 which will either be Male or Female depending on your field choices).
Equals statements use the logic “=”. Use this logic if you need your branching logic to fire based on a parameter being equal to a specific choice or value such as [age] = 18 (Here we are saying age is equal to 18) the logic will only fire if age is equal to 18. Or you can have [sex] = '1' (Here we are saying the field “sex” is equal to choice 1).
Not statements use the logic “<>” Use this logic if your branching logic is based on a field not equaling something such as
(Here we are saying age not equal to 18). So this will fire if age is equal to anything except 18.
When to Use Quotation Marks
You must ALWAYS put single or double quotes around the values in the equation UNLESS you are using > or < with numerical values.
The field for which you are constructing the Branching Logic will ONLY be displayed when its equation has been evaluated as TRUE. Please note that for items that are coded numerically, such as drop downs and radio buttons, you will need to provide the coded numerical value in the equation (rather than the displayed text label). For example:
Branching Logic Math using Advanced Syntax
“+” add
“-” subtract
“/” divide
“>” greater than
“<“ less than
“>=” greater than or equal to
“<=” less than or equal to
Examples of all math logic
Branching Logic with Events
When you have events in your project, every variable name in your advanced syntax, need to be appended by the event name.
To locate your event name to append before a variable you go to “Define my events” and there will be a column called “unique event name”. This will be the name that needs to be appended before the variable that belongs in that event. An example of an event name is [visit_1_arm_1].
If you have multiple arms in your project, event names will be different per arm, for example if we have the event Demographics in each arm and we have two arms, then the event name will be [visit_1_arm_1] or [visit_1_arm_2].
Remember
In order for your logic to work, you need to look for the “Valid” note at the bottom of your branching logic window.
Branching logic can be used across instruments but not across projects.
If you have events enabled, ensure you append every variable with the correct event name for example [demographics][sex] = '1'. If you have arms your appended name will be different per arm.
Also thoroughly test your project to ensure your branching logic is functioning properly.
All of the branching logic syntax can be applicable in all logic boxes such as in ASI conditions, survey queue logic, and branching logic.
Head over to the next section of REDCap 101, or head back to the table of contents.