Computed Fields
Computed fields automatically calculate their values from other fields using formulas. Use them for scoring, totals, and derived values without manual data entry.
What are Computed Fields?
A computed field is a special field type that:
- Calculates automatically - Values are computed when the form is saved
- Updates on change - Recalculates whenever dependent fields change
- Cannot be edited directly - Users can't override the formula result
- Uses CEL expressions - Write formulas using Common Expression Language (CEL)
Common Use Cases
| Use Case | Example Formula |
|---|---|
| Scoring | record.data.q1 + record.data.q2 + record.data.q3 |
| Totals | record.data.subtotal * 1.1 (add 10% tax) |
| Categorization | record.data.score >= 10 ? "High" : "Low" |
| Age calculation | now.year - record.data.birth_year |
Creating a Computed Field
- Go to Data Types in your workspace
- Select a form or create a new one
- Click Add Field
- Choose Function as the field type
- Open the field's settings (select its row) and enter your formula in the CEL Expression box
- Save the form
Writing Formulas
Basic Syntax
Reference other fields using record.data.<field_slug>:
# Add three fields together
record.data.question_1 + record.data.question_2 + record.data.question_3
# Multiply two fields
record.data.quantity * record.data.price
# Conditional logic
record.data.age >= 18 ? "Adult" : "Minor"
Computed formulas run with the current record, its Member, and the now date parts. Available variables and functions vary by CEL context; see the Developer CEL reference for the full list.
Examples
GAD-7 Anxiety Scoring
The GAD-7 is a 7-question anxiety screening with scores 0-3 per question:
record.data.q1 + record.data.q2 + record.data.q3 + record.data.q4 + record.data.q5 + record.data.q6 + record.data.q7
Score Interpretation
Add another computed field to interpret the score:
record.data.total_score >= 15 ? "Severe" :
record.data.total_score >= 10 ? "Moderate" :
record.data.total_score >= 5 ? "Mild" : "Minimal"
BMI Calculator
Calculate BMI from height (inches) and weight (pounds):
(record.data.weight / (record.data.height * record.data.height)) * 703
Days Until Birthday
Calculate days remaining (simplified - uses year only):
record.data.birth_month > now.month ? record.data.birth_month - now.month : 12 - now.month + record.data.birth_month
Limitations
- No circular references - A computed field cannot reference another computed field
- No external data - Formulas can only use fields from the same form
- Missing values default to 0 - If a referenced field is empty, it's treated as 0
- No string operations - Limited to basic CEL string functions
Troubleshooting
"References unknown field"
The field slug in your formula doesn't exist. Check:
- The field slug is spelled correctly (case-sensitive)
- The field exists in this form (not a different form)
- You're using
record.data.prefix
"Cannot reference another function field"
You tried to reference one computed field from another. Computed fields can only reference regular (non-computed) fields.
Formula returns wrong value
- Check field types - Ensure numeric fields are defined as Number/Integer, not Text
- Check for nulls - Empty fields become 0, which may affect calculations
- Test with simple values - Try hardcoding numbers to isolate the issue
Field Validation
Beyond computed fields, CEL can also validate user input. Fields support a validateCel property that checks values before data is saved. For field setup, see Creating Forms; for syntax and context-specific variables, see the Developer CEL reference.