Computed Variables

Create calculated variables based on other answers.

Usage

  • Use COMPUTE: variable = expression to calculate a variable
  • Can be placed at block-level or page-level
  • Supports arithmetic expressions, conditions, and conditional string values
  • Evaluated dynamically as user answers questions

Arithmetic example

# **Monthly Expenses**
Q: Monthly rent
NUMBER
VARIABLE: rent

Q: Monthly food
NUMBER
VARIABLE: food

Q: Monthly transport
NUMBER
VARIABLE: transport

BLOCK: Summary
COMPUTE: total = rent + food + transport

# **Budget Summary**
Your total monthly expenses: **{total}**

Monthly Expenses

Monthly rent

Monthly food

Monthly transport

Conditional values

Use IF <condition> THEN <value> ELSE <value> to assign a value based on a condition. The condition uses the same syntax as SHOW_IF. Values can be quoted strings, numbers, or references to other variables.

  • Unquoted values are first looked up as variable names, then treated as string literals if no matching variable exists
  • Computed variables can reference other computed variables — they are evaluated in dependency order
  • String results can be used in text placeholders and in SHOW_IF comparisons on pages, sections, or questions
# Satisfaction

Q: How satisfied are you? (1-10)
NUMBER
VARIABLE: score

# Result
COMPUTE: level = IF score >= 8 THEN "High" ELSE "Low"

Your satisfaction level: **{level}**

Satisfaction

How satisfied are you? (1-10)

Multiple categories

For more than two outcomes, use either ELSE IF chaining in a single expression, or multiple COMPUTE statements for the same variable.

With multiple statements, start with a default value and override it with conditions in increasing specificity. Each statement is evaluated in order — a condition that is false leaves the current value unchanged.

# Satisfaction

Q: How satisfied are you? (1-10)
NUMBER
VARIABLE: score

# Result
COMPUTE: level = "Low"
COMPUTE: level = IF score >= 5 THEN "Medium"
COMPUTE: level = IF score >= 8 THEN "High"

Your satisfaction level: **{level}**

Satisfaction

How satisfied are you? (1-10)

Alternatively, write it as a single chained expression:

# Satisfaction

Q: How satisfied are you? (1-10)
NUMBER
VARIABLE: score

# Result
COMPUTE: level = IF score >= 8 THEN "High" ELSE IF score >= 5 THEN "Medium" ELSE "Low"

Your satisfaction level: **{level}**

Satisfaction

How satisfied are you? (1-10)