FeaturesCalculated Fields

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

Go to SettingsCalculated 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

FunctionDescriptionExample
upcaseUppercase{{name | upcase}} → “JOHN”
downcaseLowercase{{email | downcase}}
capitalizeFirst letter caps{{name | capitalize}}
stripRemove whitespace{{name | strip}}
splitSplit string{{email | split: "@"}}
firstFirst element{{email | split: "@" | first}}
lastLast element{{email | split: "@" | last}}
sizeLength{{name | size}}
truncateLimit length{{name | truncate: 10}}

Number Functions

FunctionDescriptionExample
plusAdd{{score | plus: 10}}
minusSubtract{{total | minus: discount}}
timesMultiply{{qty | times: price}}
divided_byDivide{{total | divided_by: count}}
roundRound{{price | round: 2}}
floorRound down{{age | floor}}
ceilRound up{{rating | ceil}}
absAbsolute value{{diff | abs}}

Date Functions

FunctionDescriptionExample
nowCurrent datetime{{now}}
todayCurrent date{{today}}
date_addAdd days{{today | date_add: 30}}
date_diffDays between{{date_diff start_date today}}
years_sinceYears from date{{years_since birth_date}}
format_dateFormat date{{created_at | format_date: "%Y-%m-%d"}}

Lookup Functions

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

  1. Go to SettingsLookup Tables
  2. Create a table (e.g., “zip_to_state”)
  3. Add key-value pairs
Key (zip)Value (state)
90210California
10001New York
60601Illinois

Using in Formula

{{lookup "zip_to_state" zip_code}}

Input: zip_code = "90210" Output: "California"


Calculation Timing

Calculated fields are computed:

  1. On lead creation - When a lead first enters the system
  2. On lead update - When source fields change
  3. On recalculation - When you trigger manual recalculation
  4. On rule change - When the formula is updated (optional)

Manual Recalculation

To recalculate all leads:

  1. Go to SettingsCalculated Fields
  2. Click Recalculate All
  3. Confirm the operation

Recalculation runs in the background. Large datasets may take several minutes.


Performance Considerations

Best Practices

  1. Keep formulas simple - Complex formulas slow down processing
  2. Limit dependencies - Deep chains of calculated fields add latency
  3. Use lookup tables - More efficient than many conditionals
  4. Cache when possible - Don’t recalculate unchanged leads

Formula Limits

LimitValue
Formula length2,000 characters
Nested conditionals5 levels
Lookup calls3 per formula
Dependency depth5 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/snapshot

Viewing History

Snapshots are stored in the lead’s activity log.


API Reference

List Calculated Fields

GET /api/calculated-fields

Create 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/recalculate

Recalculate All Fields

POST /api/calculated-fields/recalculate-all

Troubleshooting

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