Course · Lesson 06 of 20

Declare a calculation

Use a formula for a derived value and choose which inputs trigger recalculation.

Reading · Practice2 sectionsPrerequisites: Accept values, preserve drafts
Course contents

Put the result in Data

A dataFormula declares a result path, a calculation and named inputs. Other elements bind to that result rather than duplicating the arithmetic. This makes a chain such as subtotal → discount → total visible in the source.

This positional Python example is a small inline JavaScript expression. It illustrates the relationship in the gallery’s permissive profile. Named Logic, introduced in lesson 08, is used by the strict scaffold.

Python · explanatory excerpt inside a pane
pane.dataFormula(
    ".total", "price * quantity",
    price="^.price", quantity="^.quantity",
    _init=True
)

A sampled input is a choice

In the Formula gallery lesson, a gross calculation reads VAT with =. Changing VAT alone does not recalculate that result. Changing a reactive input afterwards reads the new VAT. _init requests the initial calculation.

For your own estimate, make every business dependency reactive when that is the required behavior. The example’s sampled VAT is an experiment about triggers, not a universal pricing rule.

Your turn

Try it yourself

  1. Open Formula and record the inputs and displayed results.
  2. Change VAT alone and note which results stay unchanged.
  3. Change quantity, then explain which VAT value the next calculation reads.

Check your understanding

Where should a displayed total read its value?

Show the answer and expected result

From the formula’s result path in Data. The arithmetic is declared once, and any number of displays can bind to the result. Avoid putting a result inside the same collection being aggregated.

Working examples and reference