ENGAGE HELP CENTER
Calculated answers
This page will serve as a guide to setting up calculations in the project.
Calculated answers enable the creation of underlying calculations based on participants' responses in activities. The results of these calculations are visible only to administrators in the Participants page, during data export and analysis.

You can apply calculations in Response Alerts to triage participants based on the calculated value after activity completion or on values submitted in multiple submissions. Evaluating values from multiple submissions enables a dynamic review process by considering patterns or trends across repeated inputs.

Are you working with activity-level Calculated answers?

Proceed to the section Activity-level calculated answers.
Use cases

Among countless other options, here are some examples of well-known health-related risk calculation models and index calculations that can be set up within the Engage activities with help of the Calculated answers functionality:
- Body Mass Index calculation,
- SCORE2, SCORE 2-OP CVD risk calculation,
- Breast cancer risk calculation,
- EQ-5D standardised calculation of health-related quality of life,
- Patient-reported outcome measure (PROM) scores,
- etc.
Activity question types supported in Calculation builder

Here are the question types that can be included in the equations of the Calculation builder:
- Radio Button Group
- Checkboxes
- Dropdown
- Boolean
- Single-Line Input (Input Type: Number, Date, Text)
Developing calculations

Access the Calculated answers in the upper right corner of the project page.

New calculation
The option New calculation will open a new blank calculation builder view that will have to be updated following the below steps.

1. Insert the Title of the calculation.
2. If constant values are necessary in the calculation, select the option Add in the section Constants and set them up using the available Operations.
The Operations section that contains all of the available equation templates is expanded after selecting the default value "1" or "10" in the Constants or Calculation builder field.
3. In the Calculation section, follow the logical sequence for building equations and use the available Operations to construct the required equation. All changes made in the calculation builder are automatically saved.
To add new elements to your equation, click on the round bracket on the right side of the equation.
Clicking on the round bracket will add a new element into your equation.
Supported constructs

Engage supports various calculation constructs.

Add (Sum): Use to add two numbers together.
Subtract: Use to subtract one number from another.
Multiply: Use to multiply two numbers.
Divide: Use to divide one number by another.
Negate: Use to find the opposite value of a given number.
Power: Use to multiply a number by itself a specific number of times.
Root: Use to calculate the root of a number.
Sqrt: Use to find the square root of a number.
Square: Use to square a number.
Here are some simple examples how these equations have been applied.
Here are some simple examples how these equations have been applied. Calculations are displayed when developed with help of JSON editor as seen below.
["Power", 2, 3]                   # 2^3=8
["Root", 9, 2]                    # √9=3.0
["Root", 8, 3]                    # ∛8=2.0
["Sqrt", 9]                       # √9=3.0
["Square", 4]                     # 4^2=16
Exp: Use to calculate exponential functions.
Log: Use to return the natural logarithm of a number.
Log2: Use to return the base-2 logarithm of a number.
Log10: Use to return the base-10 logarithm of a number.
This is how calculations are displayed when developed with help of JSON editor.
["Exp", 2]                        # e^2≅7.389
["Log", 2.7183]                   # ln(2.7183)≅1.0000
["Log2", 8]                       # log2(8)=3.0
["Log10", 1000]                   # log10(1000)=3.0
Round: Use to round a decimal number to a specified number of decimal places.
Here are some simple examples how these equations have been applied.
["Round", -5.123456, 2]           # -5.12
["Round", -5.123456, 0]           # -5.0
["Round", -5.123456]              # -5
Comparisons
Comparison operators allow you to compare two values and return True or False based on the condition. They serve as supportive operators for such additional constructs as If-statements and Switch-Case statements.

Equal: Use to check if two values are equal.
Greater: Use to check if the value on the left is greater than the value on the right.
GreaterEqual: Use to check if the value on the left is greater than or equal to the value on the right.
Less: Use to check if the value on the left is less than the value on the right.
LessEqual: Use to check if the value on the left is less than or equal to the value on the right.
NotEqual: Use to check if two values are not equal.
Aggregation
Aggregation functions are useful for performing calculations on a set of values and returning a single result.

Max: Use to return the maximum value in a set.
Min: Use to return the minimum value in a set.
Average: Use to return the average value of a set.
Median: Use to return the middle value of a set.
Length: Use to return the length of a set (e.g., number of items in a list).
Any: Use to evaluate items in a set and return True if any item is true; otherwise, return False.
All: Use to evaluate items in a set and return True if all items are true; otherwise, return False.
Map: Use to evaluate items in a set on the left and compare them to the value on the right. Return True if the condition is true; otherwise, return False.
Checking for membership
Functions that check for membership are helpful when verifying if an answer is part of a predefined group.

In: Use to return True if the answer is in the defined group.
Not in: Use to return True if the answer is not in the defined group.
Contains any of: Use to return True if the answer contains any element of the defined group.
Contains all of: Use to return True if the answer contains all elements of the defined group.
Contains none of: Use to return True if the answer contains none of the elements of the defined group.
Typecasting
Typecasting functions convert a variable value from one type to another.

Int: Use to convert a value into an integer.
Float: Use to convert a value into a decimal (floating-point) number.
Additional constructs
Engage also supports several additional constructs.

Constant/Question values:
a) Values provided as answers in the activity questions can be applied in calculations via the construct Constant/Question. Single-Line Input, Radio Button Group, Dropdown and Checkboxes questions can be added in calculations.
b) Defined in the Constants section these values can be used in calculations within the Constant/Question construct in the Operations list.
Linked question: Use values provided as answers in the questions of any of the project activities in the calculation. Single-Line Input, Radio Button Group, Dropdown and Checkboxes questions can be added in calculations.
If-statements: Use to return numeric values based on logical expressions. For example, you can use an If statement to check conditions and return a result accordingly.
Switch-Case statements: These can execute different scenarios based on a variable. For example, return a numeric value based on a textual input provided in survey answers.
Text: This instructs the calculation builder to treat the question response as text input, which is useful for questions with predefined answer choices and expressions checking for membership.
Construct: Linked question

The Question construct is used to design calculations that utilize data from multiple submissions of an activity. The Question construct consists of three elements.

Activity: Select the project activity where the desired question is located.
Question: Select the question that needs to be included in the equation.
Position: Select the sequence of the submission that should be taken into consideration in the equation.
The construct "Linked question" can be integrated into any Calculations builder construct that supports numerical operations by replacing the number entry field with the "Linked question" element.

If your question isn’t numeric, you may need to process them with Switch or If operations to create calculations based on participants’ responses.
Position
The Position element is a part of the Question construct that indicates the sequence of the submissions and allows to work with data from multiple different submissions of the activity. By changing the Position element, various calculations between the submissions of the activity can be performed.
[-1] : Last or most recent submission.
[-2] : Second submission from last.
[-3] : Third submission from last.
etc.
[0] : First submission of the activity.
[1] : Second submission of the activity.
[2] : Third submission of the activity.
Position intervals
It is possible to work with positive and negative submission intervals in the Position field. It is important to remember the rule about the start and stop indexes of these intervals:
- Start Index (Inclusive): The element at the start index is included in the result.
- Stop Index (Exclusive): The element at the stop index is not included in the result.

Let's take a negative interval like [-3:-1] . -3 is the Start Index which is included in the function. -1 is the Stop Index which is not included in the function. So with this interval in the Position field, the function would look at the second to last and third to last submissions.
The Position intervals will come in handy while working with Aggregation functions.

The Position intervals allow to compare multiple submissions that's relevant for such Aggregation functions as Max, Min, Median, Length, Average, Any, All, Map.
Examples
Let's take a list of submissions and draw up examples of position intervals.
Submissions (first to most recent): [0,1,2,3,4,5,6,7,8,9]
[0:4] : This Position range will find the first four submissions or submissions [0,1,2,3].
[:4] : This Position range will find the first four submissions or submissions [0,1,2,3].
[-3:-1] : This Position range will find the second and third to the last submission or submissions [7,8].
[-3:] : This Position range will find the last three submissions or submissions [7,8,9].

The Project-level Calculated answers are updated with every participant's activity submission. The trends over time can be observed in the Participant profile section.
Time-based Position intervals
It is possible to work with time intervals of when submissions have been made. The same rule of Start Index being included and Stop Index being excluded applies.
- Start Index (Inclusive): The element at the start index is included in the result.
- Stop Index (Exclusive): The element at the stop index is not included in the result.

[-1d:] : This Position range will find submissions made within the last 24 hours.
[-3d:-1d] : This Position range will find submissions made from -72h to -24h or from the day before yesterday to yesterday.
[-1h:] : This Position range will find submissions made within the last hour.
[-2w:] - This Position range will find submissions made within the last two weeks (submitted within the last 336 hours).
Review practical examples and learn how to apply the functionality.

Learn more in the Calculated answers examples page.
We use cookies in order to secure and improve the Longenesis web page functionality, as well as to optimize your experience within this page.
Please see our Privacy policy for more information on how we use the information about your use of our web page. By continuing to use this web page you agree to our Privacy Policy.