How the formula builder works

Blocks instead of text, checked as you build — and why the engine has no formula parser at all.

Formulas are assembled from blocks. You choose a function, and drop fields, values or other blocks into its slots.

Why there is no text box

There is no formula language to learn and no syntax to get wrong, because the engine has no text parser. What you build is a structured expression, and that structure is what is sent to the server and compiled to SQL.

The consequences are practical rather than philosophical:

  • A formula is checked while you build it. Types are validated slot by slot, so dropping text where a number belongs is refused at the moment you do it, not after you save.
  • A saved formula cannot be malformed. There is no state where a stored formula fails to parse.
  • Nothing you build is ever executed as SQL. The server compiles your structure against a fixed whitelist of functions; values you supply travel as parameters. A formula cannot reach the database as text.

Building one

  1. Start from the function you want, or from a quick measure if the shape is a common one.
  2. Fill its slots. Empty slots are shown, so an unfinished formula is visibly unfinished.
  3. Watch the inferred result type — it tells you what you have actually built.
  4. Name it. The name is what appears in field lists and chart legends, so write it for a reader.

Nesting

A slot can hold another block, which is how expressions of real depth get built — a conditional inside a division inside a sum. There is a limit on total size, generous enough that no reasonable formula reaches it and low enough that a runaway construction cannot be saved.

Referring to other measures

A measure can use another measure. Define "Revenue" once, then build "Revenue per customer" from it. When the definition of Revenue changes, everything built on it follows — which is the whole reason to define it once.

How the formula builder works · ChartBase Docs