Ga naar hoofdinhoud

Formula Engine

The Formula Engine powers computed columns and KPI formulas in ProBeya. It allows you to define expressions that automatically calculate values from other columns or KPI references, eliminating manual data entry and reducing errors.

Formulas follow a syntax similar to spreadsheet applications (Excel, Google Sheets) and support 28 built-in functions across four categories: logic, math, string, and date operations.

Syntax Overview​

A formula is a text expression that combines:

  • Numeric literals — integers (42) and decimals (3.14)
  • Arithmetic operators — +, -, *, / with standard precedence
  • Parentheses — ( ) for explicit grouping
  • KPI references — {KPI:Name} to pull values from other KPIs
  • Column references — {Column:Name} to reference other column values
  • Function calls — FUNCTION_NAME(arg1, arg2, ...)

Operator Precedence​

Operators follow standard mathematical precedence:

  1. Parentheses ( ) — highest precedence
  2. Multiplication and Division *, / — evaluated left to right
  3. Addition and Subtraction +, - — evaluated left to right
10 + 20 * 3 = 70 (not 90)
(10 + 20) * 3 = 90 (parentheses override)
100 / 5 / 2 = 10 (left to right)

KPI References​

Use the {KPI:Name} syntax to reference the current value of another KPI on the same board. The name must match exactly (case-sensitive).

{KPI:Good Units} / {KPI:Total Units} * 100

If the referenced KPI has no value or does not exist, the formula returns N/A rather than crashing.

tip

Use extractKpiReferences() in the API to discover which KPIs a formula depends on. The system automatically recalculates computed KPIs when any referenced KPI receives a new value.

Built-in Functions​

ProBeya's formula engine includes 28 built-in functions organized into four categories.

Logic Functions​

FunctionSyntaxDescription
IFIF(condition, then_value, else_value)Returns then_value if condition is truthy, otherwise else_value
ANDAND(value1, value2, ...)Returns true if all arguments are truthy
OROR(value1, value2, ...)Returns true if any argument is truthy
NOTNOT(value)Logical negation
SWITCHSWITCH(expr, case1, val1, case2, val2, ..., default?)Matches expression against cases, returns the paired value
COALESCECOALESCE(value1, value2, ...)Returns the first non-null argument

Examples​

IF({KPI:OEE} >= 85, "On Target", "Below Target")

SWITCH({KPI:Status}, "green", 100, "amber", 50, "red", 0, -1)

COALESCE({KPI:Primary Source}, {KPI:Backup Source}, 0)

Math Functions​

FunctionSyntaxDescription
SUMSUM(value1, value2, ...)Sum of all arguments
AVERAGEAVERAGE(value1, value2, ...)Arithmetic mean
MINMIN(value1, value2, ...)Smallest argument
MAXMAX(value1, value2, ...)Largest argument
COUNTCOUNT(value1, value2, ...)Number of non-null arguments
ABSABS(value)Absolute value
ROUNDROUND(value, decimals?)Round to N decimal places (default: 0)
FLOORFLOOR(value)Round down to nearest integer
CEILCEIL(value)Round up to nearest integer
MODMOD(value, divisor)Modulo (remainder after division)

Examples​

SUM({KPI:Line 1 Output}, {KPI:Line 2 Output}, {KPI:Line 3 Output})

AVERAGE({KPI:Week 1}, {KPI:Week 2}, {KPI:Week 3}, {KPI:Week 4})

ROUND({KPI:OEE} * 100, 1)

MOD({KPI:Batch Number}, 10)

String Functions​

FunctionSyntaxDescription
CONCATCONCAT(value1, value2, ...)Concatenate values into a single string
LEFTLEFT(text, count)Extract the first N characters
RIGHTRIGHT(text, count)Extract the last N characters
MIDMID(text, start, count)Extract a substring (1-based start position)
LENLEN(text)Length of the string
UPPERUPPER(text)Convert to uppercase
LOWERLOWER(text)Convert to lowercase
TRIMTRIM(text)Remove leading and trailing whitespace

Examples​

CONCAT({KPI:Site Code}, "-", {KPI:Line ID})

UPPER(LEFT({KPI:Batch ID}, 3))

LEN(TRIM({KPI:Comments}))

Date Functions​

FunctionSyntaxDescription
TODAYTODAY()Current date as ISO string (YYYY-MM-DD)
DAYS_BETWEENDAYS_BETWEEN(date1, date2)Number of days between two dates
FORMAT_DATEFORMAT_DATE(date, pattern)Format a date using a pattern string
ADD_DAYSADD_DAYS(date, days)Add or subtract days from a date

Date Pattern Tokens​

TokenOutput
YYYYFull year (e.g., 2026)
MMMonth, zero-padded (e.g., 03)
DDDay, zero-padded (e.g., 15)
HHHours, zero-padded (24h)
mmMinutes, zero-padded
ssSeconds, zero-padded

Examples​

DAYS_BETWEEN({KPI:Start Date}, TODAY())

FORMAT_DATE(ADD_DAYS(TODAY(), 7), "YYYY-MM-DD")

IF(DAYS_BETWEEN(TODAY(), {KPI:Due Date}) < 0, "OVERDUE", "ON TRACK")

Error Codes​

When a formula cannot be evaluated, it displays an error code in the cell — similar to Excel error indicators. Each error code identifies the specific failure type.

Error CodeDisplayDescription
REF#REF!Referenced column does not exist
CIRCULAR_REF#CIRCULAR_REF!Circular dependency detected between formula columns
DIV_ZERO#DIV/0!Division by zero attempted
TYPE#TYPE!Incompatible types for the operation (e.g., string * number)
SYNTAX#SYNTAX!Invalid formula syntax (parse error)
NULL#NULL!Referenced value is null or undefined
OVERFLOW#OVERFLOW!Numeric result exceeds safe integer range
Error Propagation

When a formula references a KPI that has no value, the formula returns null (displayed as "N/A" in the UI) rather than throwing an error. This ensures that missing data never crashes the KPI dashboard — it simply shows a placeholder until data is available.

Troubleshooting Errors​

#REF! — Check that the referenced KPI name in {KPI:Name} exactly matches the KPI definition name. Names are case-sensitive.

#CIRCULAR_REF! — KPI "A" references KPI "B", which references KPI "A" (directly or through a chain). Break the cycle by removing one of the references.

#DIV/0! — Use IF to guard against zero denominators:

IF({KPI:Total Units} > 0, {KPI:Good Units} / {KPI:Total Units} * 100, 0)

#SYNTAX! — Check for mismatched parentheses, missing operators between values, or unsupported characters.

Validation​

The formula editor validates syntax in real time as you type. A red border on the formula input field indicates a syntax error, while a green border confirms the formula is structurally valid.

Validation checks:

  1. All parentheses are properly matched
  2. All function names are recognized
  3. All KPI references follow the {KPI:Name} format
  4. Operators are placed correctly (no consecutive operators like + +)
waarschuwing

Validation confirms that the formula is syntactically correct, but it does not check whether referenced KPIs exist or have values. A formula can be valid syntactically but still return #REF! at evaluation time if a referenced KPI is deleted.

Computed KPIs​

When a formula is assigned to a KPI definition, the KPI becomes a computed KPI:

  • Manual data entry is disabled for computed KPIs
  • The value is automatically recalculated whenever a referenced KPI receives a new value
  • The data source is displayed as "formula" in the audit trail
  • Computed KPIs participate in the same traffic-light threshold system as manually entered KPIs

Creating a Computed KPI​

  1. Open a board and navigate to the KPIs tab.
  2. Click + Add KPI.
  3. Fill in the standard definition fields (name, unit, category, etc.).
  4. In the Data Source dropdown, select formula.
  5. Enter the formula expression in the formula editor.
  6. Click Validate to check syntax.
  7. Click Save. The KPI value is computed immediately.

Permissions​

ActionRequired Role
View formula resultsAny board member
Create/edit formula columnsBoard admin or workspace admin
Create/edit computed KPIsBoard admin or workspace admin
  • KPI Boards — Computed KPIs use formulas for automatic value calculation
  • Action Log — Formula-driven KPI thresholds can trigger action creation
  • CSV Import — Imported data is protected against formula injection