# Calculate (/docs/nodes/calculate)



The **Calculate** node evaluates one expression and stores the result in a named variable that every later node can read. It is how a flow derives new facts from the payload.

## When to use it [#when-to-use-it]

* Derive a ratio or a total: `debt / income`, `price * quantity`.
* Compute once and reuse: the next conditions and the output read the variable.

## How it works [#how-it-works]

<Diagram node="calculate" kind="anatomy" />

1. The expression is evaluated against the payload and the existing variables.
2. Arithmetic is exact decimal: `0.1 + 0.2` is `0.3`, so thresholds on money do not drift.
3. The result is stored under the variable name and the run continues through **Next**.

## Ports [#ports]

| Port   | Taken when                             |
| ------ | -------------------------------------- |
| `Next` | Always, after the variable is written. |

## Configuration [#configuration]

| Field      | What it does                                                                    |
| ---------- | ------------------------------------------------------------------------------- |
| Name       | Label shown on the canvas and in the trace.                                     |
| Variable   | Where the result is stored. Reading it later uses this name.                    |
| Expression | A formula over payload fields, variables and project constants (`global.rate`). |

## What it writes [#what-it-writes]

One variable: `vars.<variable>`. The trace shows the formula and the value, for example `dti = debt / income`.

## In a real flow [#in-a-real-flow]

<Diagram node="calculate" kind="example" />

A calculation derives the debt ratio, a condition compares it with the limit, and high ratios go to a manual review before the output.

## When it fails [#when-it-fails]

* The expression cannot be evaluated: `EXPRESSION_FAILED`.
* A missing variable name or expression is an error in Checks.

## Good to know [#good-to-know]

* Writing a variable that already exists replaces it. A variable also shadows a payload field with the same name.
* To build a list, use [Append to array](/docs/nodes/append-to-array).

## Related [#related]

* [Expressions](/docs/concepts/expressions)
* [Condition](/docs/nodes/condition)
