Configure Calculated Fields
Calculated fields let you compute derived values from the user’s answers. These values can be used in rules, displayed on screen, or passed to the pricing engine.
A calculated field is a formula. For example, BMI = weight divided by (height times height). You define it by listing the math operations and telling the system where each value comes from — either from a question answer or a fixed number.
How to add a calculated field
Section titled “How to add a calculated field”- Open your questionnaire in Strapi
- Scroll to the calculatedFields section
- Add an entry with:
- field — The name of the computed value (e.g.,
bmi) - calculation — A JSON object defining the math
- field — The name of the computed value (e.g.,
Calculation structure
Section titled “Calculation structure”The calculation JSON defines a chain of operations. Each operation takes values and produces a result.
Example 1: BMI calculation
Section titled “Example 1: BMI calculation”Formula: BMI = weight / (height_in_m x height_in_m)
Given questions weight (in kg) and heightInMeters (in m):
{ "field": "bmi", "operations": [ { "type": "DIVIDE", "values": [ { "type": "dynamic", "value": "weight" }, { "type": "operation", "operation": { "type": "MULTIPLY", "values": [ { "type": "dynamic", "value": "heightInMeters" }, { "type": "dynamic", "value": "heightInMeters" } ] } } ] } ]}{ "type": "dynamic", "value": "weight" }means “use the answer from theweightquestion” (from a question answer){ "type": "static", "value": 100 }would mean “use the fixed number 100” (a fixed number){ "type": "operation", ... }means “calculate this sub-formula first, then use the result”
Example 2: Annual premium from monthly price
Section titled “Example 2: Annual premium from monthly price”Formula: Annual premium = monthly price x 12
Given a question monthlyPrice:
{ "field": "annualPremium", "operations": [ { "type": "MULTIPLY", "values": [ { "type": "dynamic", "value": "monthlyPrice" }, { "type": "static", "value": 12 } ] } ]}Here, monthlyPrice comes from a question answer, and 12 is a fixed number.
Operations
Section titled “Operations”| Operation | Description |
|---|---|
DIVIDE |
Divides value 1 by value 2 |
MULTIPLY |
Multiplies all values together |
ADD |
Adds all values together |
SUBTRACT |
Subtracts value 2 from value 1 |
Value types
Section titled “Value types”| Type | Description | Example |
|---|---|---|
dynamic |
From a question answer — references a questionId | { "type": "dynamic", "value": "weight" } |
static |
A fixed number that you specify | { "type": "static", "value": 100 } |
operation |
A nested operation (for complex formulas) | See BMI example above |
Using calculated fields in rules
Section titled “Using calculated fields in rules”Once defined, reference the calculated field’s field name as a questionId in your rules:
- rule-comparison: questionId
bmi, OperatorgreaterThan, Value40
The rule engine evaluates the calculated field and compares the result like any other answer.
See also
Section titled “See also”- Configure Rules – use calculated fields as rule conditions
- Questionnaire Metadata Reference – where calculated fields sit in the questionnaire structure
- Rule Evaluation – how the rule engine uses calculated field values