Calculated Fields
Calculated fields let you create dynamic field values based on formulas, other fields, or external data.
Overview
A calculated field automatically computes its value based on:
- Other lead fields
- Static values
- Date/time functions
- Conditional logic
- Lookup tables
Example: Create a full_name field that combines first_name and last_name.
Creating Calculated Fields
Navigate to Calculated Fields
Go to Settings → Calculated Fields
Click Add Field
Click the Add Calculated Field button
Configure the Field
- Name: Field identifier (e.g.,
full_name) - Label: Display name (e.g., “Full Name”)
- Formula: The calculation logic
- Type: Output type (text, number, date, boolean)
Test the Formula
Enter sample data to verify the output
Save
Click Save to create the field
Formula Syntax
Field References
Reference other fields using double curly braces:
{{first_name}}
{{custom_fields.program_interest}}
{{email}}String Concatenation
Combine text and fields:
{{first_name}} {{last_name}}Input: first_name = "John", last_name = "Doe"
Output: "John Doe"
Conditional Logic
Use if/else for conditional values:
{{if state == "CA"}}West Coast{{else}}Other Region{{/if}}{{if age >= 18}}Adult{{else}}Minor{{/if}}Default Values
Provide fallbacks for empty fields:
{{first_name | default: "Unknown"}}Common Formulas
Full Name
{{first_name}} {{last_name}}Email Domain
{{email | split: "@" | last}}State from Zip Code
{{lookup "zip_to_state" zip_code}}Age from Birth Date
{{years_since birth_date}}Lead Score
{{if source == "web"}}10{{else}}5{{/if}} +
{{if phone}}5{{else}}0{{/if}} +
{{if email_verified}}10{{else}}0{{/if}}Registration Status
{{if program_code && start_date}}Ready to Register{{else}}Incomplete{{/if}}Formula Functions
String Functions
| Function | Description | Example |
|---|---|---|
upcase | Uppercase | {{name | upcase}} → “JOHN” |
downcase | Lowercase | {{email | downcase}} |
capitalize | First letter caps | {{name | capitalize}} |
strip | Remove whitespace | {{name | strip}} |
split | Split string | {{email | split: "@"}} |
first | First element | {{email | split: "@" | first}} |
last | Last element | {{email | split: "@" | last}} |
size | Length | {{name | size}} |
truncate | Limit length | {{name | truncate: 10}} |
Number Functions
| Function | Description | Example |
|---|---|---|
plus | Add | {{score | plus: 10}} |
minus | Subtract | {{total | minus: discount}} |
times | Multiply | {{qty | times: price}} |
divided_by | Divide | {{total | divided_by: count}} |
round | Round | {{price | round: 2}} |
floor | Round down | {{age | floor}} |
ceil | Round up | {{rating | ceil}} |
abs | Absolute value | {{diff | abs}} |
Date Functions
| Function | Description | Example |
|---|---|---|
now | Current datetime | {{now}} |
today | Current date | {{today}} |
date_add | Add days | {{today | date_add: 30}} |
date_diff | Days between | {{date_diff start_date today}} |
years_since | Years from date | {{years_since birth_date}} |
format_date | Format date | {{created_at | format_date: "%Y-%m-%d"}} |
Lookup Functions
| Function | Description | Example |
|---|---|---|
lookup | Table lookup | {{lookup "states" zip_code}} |
Field Dependencies
Calculated fields can depend on other calculated fields:
full_name = {{first_name}} {{last_name}}
greeting = Hello, {{full_name}}!Order matters: Dependencies are resolved automatically, but circular dependencies will error.
Avoid circular dependencies: Field A cannot reference Field B if Field B references Field A.
Lookup Table Integration
Use lookup tables for data transformations:
Creating a Lookup
- Go to Settings → Lookup Tables
- Create a table (e.g., “zip_to_state”)
- Add key-value pairs
| Key (zip) | Value (state) |
|---|---|
| 90210 | California |
| 10001 | New York |
| 60601 | Illinois |
Using in Formula
{{lookup "zip_to_state" zip_code}}Input: zip_code = "90210"
Output: "California"
Calculation Timing
Calculated fields are computed:
- On lead creation - When a lead first enters the system
- On lead update - When source fields change
- On recalculation - When you trigger manual recalculation
- On rule change - When the formula is updated (optional)
Manual Recalculation
To recalculate all leads:
- Go to Settings → Calculated Fields
- Click Recalculate All
- Confirm the operation
Recalculation runs in the background. Large datasets may take several minutes.
Performance Considerations
Best Practices
- Keep formulas simple - Complex formulas slow down processing
- Limit dependencies - Deep chains of calculated fields add latency
- Use lookup tables - More efficient than many conditionals
- Cache when possible - Don’t recalculate unchanged leads
Formula Limits
| Limit | Value |
|---|---|
| Formula length | 2,000 characters |
| Nested conditionals | 5 levels |
| Lookup calls | 3 per formula |
| Dependency depth | 5 levels |
Snapshots
Create point-in-time snapshots of calculated values:
Use Cases
- Lock in a value at a specific date
- Track how calculated values change over time
- Create historical records
Creating Snapshots
POST /api/calculated-fields/:id/snapshotViewing History
Snapshots are stored in the lead’s activity log.
API Reference
List Calculated Fields
GET /api/calculated-fieldsCreate Calculated Field
POST /api/calculated-fields
{
"name": "full_name",
"label": "Full Name",
"formula": "{{first_name}} {{last_name}}",
"type": "text"
}Recalculate Field
POST /api/calculated-fields/:id/recalculateRecalculate All Fields
POST /api/calculated-fields/recalculate-allTroubleshooting
Field Shows Empty
- Check that source fields have values
- Verify formula syntax is correct
- Ensure dependencies are calculated first
Unexpected Value
- Test the formula with sample data
- Check conditional logic order
- Verify lookup table has the expected keys
Performance Issues
- Simplify complex formulas
- Reduce dependency chains
- Use lookup tables instead of many conditions