Skip to content

Formulas

Formulas let a property compute its value automatically on every save, based on data from the same entity, its parents, its children, or entities that reference it.

To use a formula: set the formula flag on a property definition and write the expression as the formula value. Computed properties cannot be edited manually and are skipped when duplicating an entity.

Formulas are evaluated in two passes so that properties depending on other formula properties resolve correctly.

INFO

Two-pass evaluation means a formula can safely reference another computed property on the same entity. The first pass resolves simple fields; the second resolves dependencies between computed properties.

Syntax

A formula is written as space-separated values followed by an optional function name:

field1 field2 field3 FUNCTION

If no function is specified, CONCAT is used by default.

Nested Formulas

Use parentheses to nest formulas and create complex calculations:

(field1 field2 SUM) (field3 field4 SUM) MULTIPLY

Inner formulas are evaluated first, then their results are used in the outer formula. Nesting can be multiple levels deep.

Examples:

  • (price tax SUM) quantity MULTIPLY — Calculate total with tax per quantity
  • ((a b SUM) (c d SUM) MULTIPLY) 100 DIVIDE — Complex nested calculation
  • (min_value max_value SUM) 2 DIVIDE — Average of min and max

Field References

Same Entity

ReferenceResolves to
propertyNameValue(s) of that property on the current entity
_idThe current entity's ID
'literal' or "literal"A string literal
123 / 45.67A numeric literal

Referenced Entities

ReferenceResolves to
propertyName.*.propertyProperty value from all entities referenced by propertyName
propertyName.type.propertyProperty value from referenced entities filtered by entity type
propertyName.*._idIDs of all referenced entities
propertyName.type._idIDs of referenced entities filtered by type

Child Entities

ReferenceResolves to
_child.*.propertyNamepropertyName from all child entities
_child.typeName.propertyNamepropertyName from child entities of a specific type
_child.*._idIDs of all child entities
_child.typeName._idIDs of child entities of a specific type

Referrer Entities

Entities that reference this entity through their own reference properties:

ReferenceResolves to
_referrer.*.propertyNamepropertyName from all entities that reference this entity
_referrer.typeName.propertyNamepropertyName from referrers of a specific type
_referrer.*._idIDs of all referrer entities
_referrer.typeName._idIDs of referrer entities of a specific type

Functions

FunctionDescription
CONCATJoins all values as strings (default when no function is specified)
CONCAT_WSJoins values with a separator — the last value is used as the separator
COUNTReturns the number of values
SUMSums all numeric values
SUBTRACTSubtracts remaining values from the first
MULTIPLYMultiplies all values together
DIVIDEDivides the first value by the rest. Returns undefined if dividing by zero.
AVERAGEReturns the arithmetic mean
MINReturns the smallest value
MAXReturns the largest value
ABSReturns the absolute value of the first value
ROUNDRounds to N decimal places — the last value is used as N

WARNING

DIVIDE returns undefined when the divisor is zero. Handle this in downstream formulas or ensure the divisor is always non-zero.

Examples

Full name from two fields:

first_name last_name ' ' CONCAT_WS

Total price:

price quantity MULTIPLY

Price with tax, per quantity:

(price tax SUM) quantity MULTIPLY

Count child entities:

_child.*._id COUNT

Average price across children:

_child.*.price AVERAGE

Round result to 2 decimals:

(total quantity DIVIDE) 2 ROUND

Profit from referrer invoices:

_referrer.invoice.amount SUM