Frequently Asked Question (FAQ) Library
FAQ: Calculate Text Field (v1,0, 07/21/23)
Page 1 of 3
Tags: Features Basic, Action Tags
The @CALCTEXT action tag evaluates specified logic for text fields and outputs the result as text. It is
usually used with an if (x,y,z) function, where if x is true, then y, else z.
Example #1: Conditional piping used to customize lookback timeframes.
In the following example, we want to customize the timeframe for lookbacks at each event (visit). For the
baseline questionnaire, we will ask about medications prescribed in the past year. For the follow-up
questionnaire, we will ask about medications prescribed in the past month.
To perform a calculation on text fields with conditional piping, we will add a hidden field and use the
@CALCTEXT action tag to ‘calculate’ the text that will be used for piping based on the event.
a. Within the ‘Designerin the left navigation menu, add a text box field for the calculation.
b. In the action tag box, add the @HIDDEN and @CALCTEXT action tags. The @HIDDEN action tag will
hide the field on the form.
For the @CALCTEXT tag, add the following syntax:
@CALCTEXT(if([event-name]=’baseline_arm_1’, ‘in the last year’, ‘in the last month’))
The action tag box should look like this:
Notes:
i. You must use text box field type for @CALCTEXT calculations. Do not use calculated field type.
ii. In this example, a smart variable, [event-name], is used; however, project-specific variables
can also be used. In instances where the evaluated field is multiple choice, use the numeric
code for the choice you want to reference.
iii. When referencing the value of a text field, it must be contained within quotes or apostrophes.
iv. @CALCTEXT action tag can also be used without conditional logic. For example, it can be used
with other text functions to concatenate text or extract text from other text field.
How do I perform a calculation on text fields?
If the event is baseline,
the calculated value
will = in the last year
For all other events, the
calculated value will = in
the last month
Frequently Asked Question (FAQ) Library
FAQ: Calculate Text Field (v1,0, 07/21/23)
Page 2 of 3
Tags: Features Basic, Action Tags
c. When the @CALCTEXT is created, you will pipe the calculated field into the survey question.
To learn more about piping, refer to FAQ: PIPING.
d. Once these steps are completed:
a. In the baseline event, this question will appear:
b. In the follow-up event (non-baseline), this question will appear:
Pro Tip: If after a data import, your calculated fields do not appear to update, run the Data Quality rule
H. This will evaluate all calculated fields for accuracy. Select View to see the results of the data quality
test and then select Fix Calcs Now. REDCap will correct all incorrect calculations.
Frequently Asked Question (FAQ) Library
FAQ: Calculate Text Field (v1,0, 07/21/23)
Page 3 of 3
Tags: Features Basic, Action Tags
Example #2: Populate a site name field based on the Data Access Group (DAG)
To learn more about Data Access Groups, refer to FAQ: DAGs.
In the following example, we will identify the recruitment ‘site’, based on the data access group (DAG)
assigned to that the record. To reference a DAG, use the Smart Variable [record-dag-name]. The DAG
name of each data access group can be found on the DAG page under the column ‘Unique group name’.
1. Within the ‘Designer, create a text field for the ‘Site’. Use @CALCTEXT action tag with [record-dag-
name] to calculate the site, if any.
2. This CALCTEXT statement will result in the following value being displayed for the ‘BPT’ DAG:
Pro Tip: This type of calculated text
field, i.e. a field used for
identification, can be useful for
adding branching logic to survey
questions based on the recruitment
site (or other variables).