A Practical Guide to Scoring, Dates, and Dynamic Values
Automatically calculate values based on data entered in your project
Calculated fields allow REDCap to automatically compute values in real time using data from other fields. They are commonly used for scoring instruments, calculating age or time intervals, and generating derived variables for analysis.
Core Principle: Calculated fields always return a numeric value based on a formula using other fields.
⚠️ Important: Calculated values are not automatically saved for existing records when you change a formula. You must run Data Quality Rule H to update stored values.
On this page
What Calculated Fields Do
- Automatically compute scores
- Calculate age or time differences
- Generate derived variables
- Reduce manual calculation errors
✅ Best Practice: Use calculated fields for simple, real-time calculations—not complex data processing.
Calculation Syntax
Basic format:
[field1] + [field2]
Examples:
[bp_sys] + [bp_dia] [bmi_weight] / ([height]^2) if([age] > 65, 1, 0)
Tip: Use square brackets for all variables.
Common Functions
sum()mean()min(),max()round()if()
sum([q1],[q2],[q3]) round([value],1) if([score] > 10, 1, 0)
sum() vs +
| Method | Behavior |
|---|---|
| + | Fails if any field is blank |
| sum() | Ignores blanks |
⚠️ Important: Choose based on scoring rules.
Working with Dates
datediff([dob],[visit_date],"y")
datediff("today",[visit_date],"d")
- y = years
- d = days
- M = months
⚠️ Important: “today” updates each time the record is opened.
Checkbox Calculations
if([exercise(1)] = 1, 1, 0)
⚠️ Important: Checkbox values are binary (0/1), not choice codes.
Real-World Examples
Total Score
sum([q1],[q2],[q3],[q4])
Age
datediff([dob],"today","y")
Eligibility Flag
if([age] > 18,1,0)
Updating Values (Rule H)
- Go to Data Quality
- Run Rule H
- Click “Fix calcs now”
⚠️ Important: Updates ALL records.
div>
Common Mistakes
- ❌ Using text instead of numeric output
- ❌ Not running Rule H
- ❌ Using checkbox incorrectly
- ❌ Overcomplicating formulas
Best Practices
- Keep formulas simple
- Use sum() when appropriate
- Test thoroughly
- Avoid heavy use in large projects