Skip to content

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.

  1. Open your questionnaire in Strapi
  2. Scroll to the calculatedFields section
  3. Add an entry with:
    • field — The name of the computed value (e.g., bmi)
    • calculation — A JSON object defining the math

The calculation JSON defines a chain of operations. Each operation takes values and produces a result.

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 the weight question” (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.

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
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

Once defined, reference the calculated field’s field name as a questionId in your rules:

  • rule-comparison: questionId bmi, Operator greaterThan, Value 40

The rule engine evaluates the calculated field and compares the result like any other answer.