Goal: Display participant’s age in Months if less than 1 year old and display age in Years if they are over 12 months old. This tutorial assumes you already have 2 date fields from which to calculate the participant’s age.


Step 1. Create calculated field:

We add the following datediff logic to determine the age in Months:

datediff([date1],[date2], 'M', 'mdy')


Step 2. Create 2nd calculated field:

We add the following logic to say if the calculated age is greater than 12 months, divide by 12 to get the result in Years, otherwise display the value in Months

if([datecalc]>'12', datediff([date1],[date2],'M','mdy')/12,[datecalc])


Step 3. Create a Text field

To this field, we'll be adding the following logic which will add "Months" to the calculated age if they are less than 1 year old and "Years" if they are one year or older.

@CALCTEXT(if([datecalc]>12,(concat([may],' Years')),if([datecalc]< 12,(concat([may],' Months')),'')))


Result:

Additional:

You can add @HIDDEN-SURVEY action tag to hide these fields from the participant

You can round the calculated age to the nearest whole lumber, two decimal places, etc:

How can I round the result of my calculated field?


More information on using Null and other Conditional Logic can be found on the Help & FAQ page in REDCap


For additional assistance, please contact the REDCap Support Team


  • No labels