Skip to content

Formula Engine

Formula Expression Engine

LotusGen allows custom column derivations and conditional filtering through a secure AST sandbox that evaluates expressions without unsafe eval() calls.


Intra-Table Dependencies

A function column can reference any column defined above it in the table schema. The intra-table DAG automatically validates column evaluation order and rejects circular references.


Supported Syntax & Functions

Arithmetic Operators

  • Addition: +
  • Subtraction: -
  • Multiplication: *
  • Division: /
  • Floor Division: //
  • Modulo: %
  • Power: **

Comparison Operators

  • Equality: ==, !=
  • Inequality: <, <=, >, >=

Logical Operators

  • Conjunction: and
  • Disjunction: or
  • Inversion: not

Built-in Mathematical Functions

  • abs(x): Absolute value
  • round(x, n): Round number to n decimal places
  • min(a, b): Minimum of values
  • max(a, b): Maximum of values
  • sqrt(x): Square root

Ternary Conditionals

Python-style inline ternary expressions are fully supported:

value_if_true if condition else value_if_false

Formula Examples

Price Calculation with Tax

round(unit_price * (1 + tax_rate), 2)

Customer Tier Segmentation

'VIP' if total_spend > 1000 else 'Regular'

Full Name Concatenation

first_name + ' ' + last_name

Conditional Row Filtering (exclude_if)

Tables support an optional exclude_if formula. When generating data, if exclude_if evaluates to True for a given row, that row is omitted from the output stream:

# Example: Exclude inactive trial users with zero activity
status == 'trial' and login_count == 0