Skip to main content

Calculation recipes: formulas, ages, dates and system variables

Write a formula with the Calcul question, compute an age or a target date, display a value from another visit, and fix the error messages a calculation can return

A Calcul question computes its value from other answers. The site never types in it. You pick one of six calculation types, and Datacapt recomputes the result each time a site saves one of the source answers.

🔑 Prerequisite: eCRF Builder (Edit), and a study in Draft or Suspended status.


The six types of Calcul

Add a question, choose Calcul as the selection type, then pick a type under Select type of calcul.

Type

Use it for

Custom function

A formula: BMI, a score total, a dose per kilo

Calculate age

The age at the date the site saves the birth date

Dynamically calculated age

An age that stays current. Datacapt recalculates it each day at midnight UTC

Calculate Date / Time

A date or time at a fixed distance from another date: next visit, end of washout

Data display

Showing an answer from another form or visit inside the current form. Datacapt leaves this block out of exports

System variable

Showing the center ID, the randomization group or the treatment arm code


Write a formula

A formula combines variable names in braces, numbers, and the operators + - * / ^ ( ).

🛠️ Step by step guide

  1. Note the Variable name of each source question. The copy icon next to the variable copies it in one click.

  2. Add a Calcul question and select Custom function.

  3. Type the formula, with each variable between braces.

  4. Set Max decimal to the number of decimals you want in the result.

  5. Click Save, then test it on a draft subject.

Recipes

Need

Formula

BMI, weight in kg and height in m

{WEIGHT}/{HEIGHT}^2

BMI, height in cm

{WEIGHT}/({HEIGHT}/100)^2

Total of a five-item score

{Q1}+{Q2}+{Q3}+{Q4}+{Q5}

Mean of three blood pressure readings

({SBP1}+{SBP2}+{SBP3})/3

Dose at 1.5 mg per kg

{WEIGHT}*1.5

Percentage change from baseline

({V3_SCORE}-{V1_SCORE})/{V1_SCORE}*100

Weighted score

2*{A_1}+3*{C_1}

What a formula can read

  • Number, Rating, Slider and other Calcul questions.

  • Radio buttons and Dropdown questions. The formula reads the Value of the selected option, so give your options numeric values (0, 1, 2) when you plan to score them.

  • Questions from any visit of the eCRF, and questions from the study's ePRO forms. A site-side total of a patient questionnaire is possible.

Variable names are not case sensitive inside a formula. When a section has a prefix or a suffix, use the full name as the Builder shows it, for example {V1_WEIGHT}.

⚠️ Warning: a formula has operators and nothing else. It has no IF, no ROUND, no MIN or MAX, and no date subtraction. For rounding, use Max decimal. For a rule such as "flag when BMI is above 30", compute the BMI here, then add a Data validation on the Calcul question.

💡 Tip: a Calcul can read another Calcul. Build a long score in steps: one Calcul per sub-score, one for the total. Switch on Hide in eCRF (Advanced tab) on the intermediate steps so the site sees the total alone. The steps still come out in the export.


Compute an age

🛠️ Step by step guide

  1. Add a Date/time question for the birth date. The subtypes Date, Date and time, Year and month and Year all work.

  2. Add a Calcul question and select Calculate age.

  3. Link it to the birth date question.

  4. Click Save.

Pick Dynamically calculated age when the age must stay true over a long follow-up, for example a paediatric cohort with age-dependent forms. Pick Calculate age when you want the age frozen at inclusion.


Compute a target date

Calculate Date / Time adds a period to a reference date. Typical uses: the target date of the next visit, the end of a washout, the latest time for a post-dose sample.

🛠️ Step by step guide

  1. Add a Calcul question and select Calculate Date / Time.

  2. Link the reference Date/time question.

  3. Under Calculate Date / Time after, enter the amount.

  4. Choose the Period type: Minutes, Hours, Days, Months or Years.

  5. Click Save.

Example: reference {V1_DATE}, amount 14, period Days. The site reads the target date of visit 2 as soon as it saves the visit 1 date.

💡 Tip: to check that a visit happened inside its window, add a Data validation on the visit date question with the date operators Less than (after) or More than (after) and Date linked to the reference visit date. See Build automated queries with data validation.


Show an answer from another visit

Data display writes answers into a sentence. Type your text and insert variables in braces: Weight at screening: {V0_WEIGHT} kg. It accepts text, checkbox and date answers as well as numbers. Datacapt does not export this block.

Show the center, the group or the arm

System variable accepts one of three variables per question: {CENTERID}, {RANDOMIZATIONGROUPID} or {TREATMENTARMCODE}.

⚠️ Warning: {TREATMENTARMCODE} shows the arm to anyone who can see the question. In a blinded study, restrict it with Role-Based Visibility on the Advanced tab.


When the result is empty or shows an error

Message

Cause

Fix

Not all variables have answers

A source question is still empty

Complete the source question. The result fills in on save

Fill out previous fields

Same cause, shown before any source holds an answer

Same

Calcul formula is in incorrect format

A bracket or an operator is missing in the Builder

Check brackets and operators

Unsupported characters in function

The formula holds a letter, a comma or a function name outside braces

Keep digits, braces and + - * / ^ ( ). Use a point for decimals

Variables in questions does not match variables in calcul question

A variable in the formula no longer exists, often after a rename

Update the formula with the new variable name

Formula contains empty variables

Empty braces {}

Type the variable name between the braces

Answer required for calcul has invalid data format

A source answer is not a number, for example an option with a text value

Give the option a numeric Value

Error during evaluation of formula

Division by zero, in most cases

Add a data validation on the divisor to refuse 0

Result of formula is too big number

The result exceeds the platform maximum, or an exponent exceeds 100

Check the units of your sources

No answer for reference question

The date linked to an age or date calculation is empty

Complete the reference date

Invalid reference question

The linked question changed type or no longer exists

Link the calculation again


Limits

  • 1,000 characters per formula.

  • A Calcul can read another Calcul up to 50 levels deep. It cannot read itself.

  • Max decimal goes from 0 to 40.

  • One system variable per question.


👉🏻 Next step

Did this answer your question?