Skip to content

Formulas

MODLR uses formulas in three distinct places. They share a syntax and a function library, which makes them look interchangeable, but each one produces something different and runs at a different moment. Knowing which kind you're writing is usually the whole of the problem.

Cube formulaCard formulaSet instruction formula
Where it's writtenThe Formula Editor, against a CubeApply Formula, against one component propertyThe Set Editor, reached from any surface that uses sets
What it producesA cell's valueA property's value - text, colour, size, visibilityWhich elements appear as rows or columns, and how they're labelled and styled
When it runsWhen the cell is calculatedWhen the card rendersWhen the set is built
What it applies toEvery cell matching the formula's RestrictionsThat one propertyThe set's rows or columns
Stored inThe model, as part of the CubeThe CardWhatever holds the set - a Workview, a Card component, a Mapping, a Dashboard selectable, or an Excel SetInstruction

What they have in common

  • Function names are written in capitals - IF, LINK, ELEMENT, SPLIT.
  • A relative cube location is written in square brackets with double-quoted elements: ["Revenue","All Products"].
  • ELEMENT reads the current context, so a formula can respond to the cell, card or row it's being evaluated for.
  • VARIABLE reads a model variable or one of the built-in reserved variables.
  • & concatenates.

The Cube Functions reference is the shared library - but shared is not the same as universal. A function's reference page states the contexts it runs in, under Only Executes Under.

Functions that only run in some contexts

FunctionRuns under
RAND, RANDBETWEEN, the SQL* functions, CHILDREN, DESCENDANTS, CONTEXTDUMPCards only
NOW, TODAY, USERELEMENTACCESSCards, Workviews and Processes - not cube formulas
IRR, XIRRCube formulas only

So a card property formula can pick a random number or read the current date; a cube formula can do neither. A cube formula can calculate an internal rate of return across a range of cells; a card formula uses CUBEIRR instead.

Relative locations are literal in a cube formula

A cube formula's relative location has to resolve to element names directly - it can't be assembled from a string expression. This is valid in a card or set instruction formula, but not in a cube formula:

js
LINK("Profit and Loss", [ELEMENT("Time") & " YTD"])

Card and set instruction formulas are evaluated at render time against a known context, so they can build an element name as a string. A cube formula is compiled against the cube's structure, so the elements it references have to be nameable up front.

Where a cube formula genuinely needs an element it can't name literally, that's the job of LINKBY with a Mapping - the mapping resolves the element the formula can't determine on its own.

Checking a formula

Whichever kind you're writing, Testing and explaining formulas covers how to confirm it does what you meant - validating and testing before saving, and tracing a value back through the formulas that produced it.