Click on the magnifying glass to the right. Starting typing a topic you wish to learn about
Calculated Fields - General Overview
REDCap has the ability to make real-time calculations on data entry forms and surveys.
This article reviews the below topics:
How to Format & Create a Calculated field + reporting considerations
Calculations using (Radio Buttons or Dropdown Lists)
Calculations using (Checkboxes – select all that apply)
How to use conditional logic in a calculated field
How to use the “sum” function vs. the “+” function
BMI Calculation
How to use DATEDIFF special function to calculate the difference between two dates or date times
Use different EVENTS in calculated fields (longitudinal projects only)
Preform advanced functions in calculated fields
It is recommended that calculation field types are not excessively utilized on REDCap data collection instruments as they can slow down the webpages.
The Process
In order for the calculated field to function, it will need to be formatted in a particular way. This is somewhat similar to constructing equations in Excel or with certain scientific calculators.
The variable names/field names can be used as variables in the equation, but you must place [ ] brackets around each variable. Please be sure that you follow the mathematical order of operations when constructing the equation or else your calculated results might end up being incorrect.
Calculations in REDCap are formatted the same way as Excel, but instead of using the cell names ([A2]+[A3]), the variable names are used ([bpi_q1]+[bpi_q2]).
How do I create a calculated field?
On the Online Designer page, you would select Calculated Field as the field type. Type the calculation into the Calculation Equation box. If you have test data in the project, you can test the calculation to see if it’s valid by selecting a study ID from the Test calculation with a record dropdown list.
Can I create a calculation that returns text or a date as a result (Ex: "True" or "False," “[visit_date] + 30 days”)?
No, calculations can only result in numbers.
What mathematical operations are available for calculated fields?
Null or blank values can be referenced using ”” or “NaN”
How you code a calculation can determine if it will display on a report.
In the below equations, both will provide an answer on the form. However if it is desired that the calculation display on a report, you must use nested "if's" and can not use the "or" function.
The below calculation will show on the form but does NOT display on the report:
(if([statement2]=1,0,0) or
if([statement2]=2,1,0) or
if([statement2]=3,2,0) or
if([statement2]=4,3,0))However, this calculation (with the same calculated outcome) will show on both the form and the report:
if ([statement1]=1, 0,
if ([statement1]=2, 0,
if ([statement1]=3, 1,
if([statement1]=4, 3, 0)))
**NOTE: You must EXPAND the below sections to view the full content. Click the (>) carrot to expand.
Performing calculations on multiple choice questions (Radio Buttons or Dropdown Lists):
Performing calculations on multiple choice questions (Checkboxes – select all that apply):
Use conditional logic in a calculated field:
Using the “sum” function vs. the “+” function:
BMI Calculation:
Calculate the difference between two dates or date times: (DATEDIFF Special function)
(i.e., age at enrollment based upon DOB and date of enrollment, length of hospital stay based on admit and discharge dates): datediff([date1],[date2], "units", "date format", Return Signed Value)
Use different EVENTS in calculated fields (longitudinal projects only):
Perform advanced functions in calculated fields:
NOTE: All function names (e.g. roundup, abs) listed below are case sensitive.
**This Knowledge Article has been developed by the University of Utah’s REDCap Analysts using data garnered from the REDCap Consortium Library and other REDCap Affiliate members’ online resources and documents