What is Build My Calc? This is a tutorial to help you build your REDCap calculation one step at a time. The framework of the calculation is provided, and you fill in the blanks. How many blanks, and what kind of information is needed will depend on the calculation you want to build. As you specify the different elements, you can see them being added to the calculation in real time at the bottom of the survey page.
To get a PDF copy of your calculation, click 'Submit' once you reach the end, and you will see an option to download a PDF of the completed tutorial and calculation.
You can also click the "Save and Return Later" button, where you can enter your email address and a private link to this survey will be sent to you. You can access that link and your calculation anytime (no return code needed).
You may need to adjust the calculation further once it is in your project. Each project is different, and while the formatting for calculations is fairly standard, you may need to make further adjustments.
Click on the buttons below to learn more:
Build My Calc Information
This tutorial has five different functions to create calculations with. You can combine certain functions if you like. There are more functions available in REDCap, but this tutorial only includes the most common functions and combinations of those functions.
See the fields below for more information on each these functions, and to learn how they work.
If you are building a complex calculation in REDCap, you may need more help than this tutorial can provide and you should contact redcap@bcchr.ca for assistance. How REDCap Calculations work:
REDCap can automatically pull data from fields across your project, perform a function, and then display an output. Calculations must be formatted in a particular way, which this tutorial will help you with.
Calculations in REDCap:
work in real time
can pull data from different instruments and events
only compute numbers and dates
work in data entry forms and in surveys
can only output numbers
Click on any of the calculations below to learn more about how they work:
Date Difference Function
What is it?
Use this function to calculate the difference between two date or datetime fields.
When would you use it?
Some common examples include: To calculate a participant's age, to know the time lapse between two clinic visits, or to send surveys after a certain amount of time. Basically anytime you want to display a time difference.
How does it work?
Specify two date variables and an output format to get the difference between them. At least one or both date or datetime fields must exist as variables in your project and be validated as date or datetime fields. If you don't have two date fields, you can use 'today' or a fixed date as the second date field.
Can I use today's date as a variable?
Yes. Using 'today' is a great way to calculate the difference between a date field and today's date, but 'today' can cause data quality issues , as any time you open and save a form using 'today' in a calculation, that calculation will automatically take today's date and update your calculation. Only use 'today' if it's necessary.
What does a date difference calculation look like?
If you put your date difference equation in a calculated field, the number output will appear in red and in the units you specify:
Round Function
What is it?
Use this function to round a number to a certain decimal point.
When would you use it?
Anytime you want to round a number. You can add this function to any calculation, including a date difference calc, a mean function, or BMI calculation.
How does it work?
All you need to do is specify how many decimal points you want your output to round to at the end of calculation.
Can this function be combined with other functions?
Yes. It is common to use the round function with a BMI calculation, an average, or any number output.
What does a round function look like?
The number will round to whatever decimal point you specify:
If/Then Statement Function
What is it?
Use this function to create conditional logic and generate an output based on the logic you specify. In its simplest form, the IF function says:
IF(Something is True, then do something, otherwise do something else)
So an IF statement can have two results. The first result is if your comparison is True, the second if your comparison is False.
When would you use it?
Some common examples include: to create ranges for raw values- so I can have a calculation take a raw value, say from 0-100 and convert that into a number on a scale, say from 1-10. It could also be used to give you a certain output (this output will always be a number) based on another calculation.
For example: An IF statement can compare data that I have in a variable against a condition. My variable, let's call it [score], could be a radio button, a short text box validated as a number field, or another calculation. In this case, my condition is '10'.
So I want to write if([score]='10', 1, 0). This statement says that if my "score" variable equals 10, then display 1, if "score" does not equal 10, display a 0. So I won't see the score- what I will see are my defined outputs.
How does it work?
An IF statement is a comparison. Here you are defining what data the statement will pull to use in the comparison. In REDCap, you want the comparison to be done against a variable that exists in your project. This variable must be a radio button or text box that is validated as a number field. Calculations cannot read or compute text fields. The calculation input and output will always be a number.
Can I create nested if statements?
IF statements may be used inside other IF statements ("nested"). For example, if you wanted a calculation to help assess participant eligibility and consent, you could do the following:
if([consent]="yes",1,if([eligible]="yes",2,0))
This statement says that IF the consent is marked yes, then show '1', IF not, then calculate IF eligibility is marked as yes, show '2', and if not, then show '0'.
What does an if/then statement look like?
Once your if statement is added as a calculated field, you will see the numerical output in red:
Sum Function
What is it?
Use this function to add up any variables in your project (except text fields and check boxes).
When would you use it?
Some common examples include: adding up scores on a scale, adding up answers to a quiz, adding up data across events.
How does it work?
The fields you want to include in the sum calculation must exist as variables in your project. You can sum up radio buttons, drop down menus, text fields validated as numbers, and other calculated fields. The calculation will add up the raw values assigned to the answer options.
Can I use reverse coding in a sum calc?
Yes, make sure your answer options are coded according to the meaning of the question and that the coding is consistent. This way when you go to add them up, the score is reflective of the data meaning.
Can I sum up checkboxes?
No. Do not include checkboxes in your sum equation, as checkboxes function differently and the raw value will always be either '1' (checked) or '0' (unchecked) as opposed to other fields, where you can specify the raw number value.
Why can't I just add up variables like this: [variable1] + [variable2]?
This works too. However, if one or more of the variables is blank, then the above calculation won't work (it will be blank with no output). The sum function will take whatever values are filled out, ignore any blank values, and give you an output.
What does a sum function look like?
Once your sum calc is added as a calculated field, you will see the numerical output in red:
Mean Function
What is it?
Use this function to calculate the mean for any variables in your project (except text fields and check boxes).
When would you use it?
Anytime you want the mean score from multiple numerical fields.
How does it work?
Returns the mean (i.e. average) value of a set of values provided in the format mean([num1],[num2],[num3],...). The fields you want to include in the mean calculation must exist as variables in your project. You can use radio buttons, drop down lists, text fields validated as numbers, and other calculated fields. The calculation will average the raw values assigned to the answer options.
Can I average checkboxes?
No. Do not include checkboxes in your mean equation, as checkboxes function differently and the raw value will always be either '1' (checked) or '0' (unchecked) as opposed to other fields, where you can specify the raw number value.
What does a mean function look like?
Once your mean calc is added as a calculated field, you will see the numerical output in red: To start building your calculation, click the 'Next Page' button below
Next Page >>
Save & Return Later