name: op-overlay-formula
kind: operator
category: OVERLAY
operator: OVERLAY_FORMULA
description: Expression-driven overlay evaluated per host coordinate against a per-host-shape variable namespace.
type: reference
applies_to: process, compose
examples_tags: [overlay, feature-engineering]
An expr-lang/expr expression evaluated per host coordinate. The variables, functions and refusal codes on each host: overlay-formula-namespace.
Use when
Computes a custom figure for every cell, group or total from an expression over the value and its margins, totals or prior point.
Questions it answers:
- Can I show each cell as its gap from the row margin divided by the grand total?
- Can I flag each month whose value is more than 10% above the prior month?
Use something else:
ATTR_FORMULAwhen you need a derived field on every row before aggregation.
Params
| Name | Type | Default | Description |
|---|---|---|---|
field | string | — | SERIES host: the OUTPUT LABEL read as value (Compose: and ref_value, slot.<label>.value, per slot) or one element column "<label>[<element label>]"; absent, the first aggregation. |
partition_by | list | — | Over two or more groupers (Compose: the first target’s), the leading group key columns each partition shares (default all but the last; [] = one walk). |
formula | string | (required) | The expression; absent, empty or not a string → PULSE_OVERLAY_PARAM_MISSING, unparsable → PULSE_OVERLAY_FORMULA_PARSE_ERROR. |
baseline_position | int | — | SERIES host: the 0-based row of each partition baseline reads. |
scope — cell (MATRIX) / group (SERIES) / total (SCALAR).
Host shape
overlays on a crosstab (cell, margin_*, sd_*) or a grouped Process (value, total, prior, baseline; empty ref; per partition over N ≥ 2 groups); Compose on the first target against a reference of any shape (ref_cell / ref_value / ref, slot.<label>.*). Ungrouped → PULSE_OVERLAY_REF_INCOMPATIBLE_WITH_SHAPE.
Output
Shape matches the host; one number per evaluation (a bool reads 0 / 1). No summary.baseline.
Contract
- Weight: not read; a weight in force is skipped.
- Streaming: buffered only.
Gotchas
- A NaN MATRIX host cell is MISSING: never evaluated, the cell stays absent, no warning.
- A name outside the namespace is
PULSE_OVERLAY_FORMULA_INVALID_IDENT(+ allowed set), predict and runtime; a non-numeric result isPULSE_OVERLAY_FORMULA_TYPE_MISMATCH. - No vector functions;
total(expr)isPULSE_FORMULA_TOTAL_SITEhere (use thetotalvariable). EmbedderExprFunctionswiden functions, never variables. - Margins, totals and SDs are post-fold, hence buffered.
- A crosstab (
overlaysor a Compose slot) reads cell values: a code cell (AGG_MODEovercategorical_*/packed_bool— the modal dictionary index / truth value) →PROCESSING_CONFIG, reasoncategorical_code(+field,field_type; the cell path inslot/ Composehost), predict and runtime. Use a count cell.
See
- Skills:
overlay-formula-namespace,overlay-system,op-attr-formula;docs/src/internals/extension-points.md.