Table of Contents
A calculation field allows you to specify a formula or calculation about variables present within the study.
To make calculations with values of different fields, it must be possible to reference other fields, and this is done by using the Variable name entered into the study fields.
To create a calculation field, select the appropriate button in the Form Builder Field List:
Within the dialog window, complete the field as normal.
The Calculation template box is used to specify the formula/calculation you wish to perform. To reference other fields, place braces '{ }' around the field variable name e.g. {INCL03}.
See the image below for a full example:
Calculation fields update automatically, but the update behavior depends on how the data is entered and where the fields are located.
Data Entered Manually via the Web Browser
When users enter data directly into the user interface, the system behaves differently depending on form layout:
Scenario A: Fields are on the Same Form
If the calculation field and its referenced fields (for example, Weight, Height, and the BMI calculation) are located on the same form:
Instant Updates: The calculation is computed instantly by the web browser (on the frontend) as data is entered.
User Action: Because this process bypasses the backend database engine, a user with the Edit permissions must actively open and view the form for the calculation to run and save.
Scenario B: Fields are on Different Forms
If the calculation field is on a different form (or a hidden/blinded form) from the referenced fields (for example, Weight and Height are on the "Baseline" form, but the BMI calculation is on a separate "BMI" form):
Background Processing: The system's backend engine automatically takes over. It queues the calculation and processes it asynchronously.
User Action: You do not need to open the destination form to trigger the update; it updates silently in the background.
Data Entered via API, Data Import, or Automations
If data is entered into the system programmatically (bypassing the manual user interface):
Automated Backend Updates: Because there is no active browser session to run frontend JavaScript, the backend engine automatically steps in to compute the calculations.
Form Location Doesn't Matter: The backend will successfully process and update all calculations, even if the referenced fields and the calculation field reside on the same form. No manual form opening is required to trigger the update.
To ensure that every value is updated, make sure to enable it from the Study Settings:
Common JavaScript syntax
To get you started, here are a few common JavaScript operators to use for basic calculations along with their description.
| Description | Operator |
| Variable | {Variable} |
| Addition | + |
| Subtraction | - |
| Division | / |
| Multiplication | * |
|
Exponential (x to the power of y) |
Math.pow(x, y) |
| Equal to | == |
| Not equal to | != |
| Greater than | > |
| Greater than or equal | >= |
| Less than | < |
| Less than or equal | <= |
| Logical "AND" | && |
| Logical "OR" | || |
Referring to surveys and repeating data
It is also possible to base the calculations in study forms upon data entered in a survey or a repeating data.
When creating the calculation field, enter the variable names defined in your survey fields or in repeating data.
For example, using responses from a survey where the patient provides information about weight and height with variable names {surv_pat_weight} and {surv_pat_height}.
These variables can be used to create a calculation field inside the study forms that refers to that field, for example:
{surv_pat_weight}/Math.pow({surv_pat_height},2)
Note: Castor can only calculate in reference to the latest filled in version of a survey or last completed repeating data.
This means that it is not possible for calculations to refer to different versions of a survey or instances of repeating data inside a participant’s record, only to the most recent version provided.
Surveys: Learn how to use survey responses in your study form calculations by reading Can I use calculations in surveys in EDC/CDMS?
Repeating Data: Learn how to configure calculations within or across repeating instruments in Can I use calculations in repeating data in EDC/CDMS?