Variables
User Guides › Matrix Forge
| ← Previous: Formula syntax | Next: Output matrices → |
Variables (pre-calcs)
Variables are the first phase of the calc engine. They run before output matrices and are meant for intermediate values, lookups, and expressions you reuse in many formulas.
Purpose
- Pre-calculations — Compute a value once and reference it as
Var.Namein matrix columns or output variables. - Re-used values — e.g. discount factor, base premium, or a data-sheet lookup used in multiple columns.
- Lookups — Use
DataSheet(...),DataSheetLookup(...), orRate(...)in a variable so matrix formulas stay simple.
Variables are not included in the Data Schema output; they are internal to the engine. Only output matrices and output variables can be marked for schema inclusion.
Defining variables
In the Variables tab:
- Name — Unique identifier. Use valid C#-style names (letters, numbers, underscore). Referenced in formulas as
Var.Name. - Formula — Expression that can use
Input.*,Rate(...),DataSheet(...),DataSheetLookup(...), and any other syntax described in Formula syntax. It cannot useRowNum,PreviousRow, orCol(those are only available in matrix row context). - Iteration update formula (if applicable) — Some engines support an optional update expression for iterative logic; use when the UI exposes it.
Order
Variables are evaluated in list order. You can reference an earlier variable in a later one: Var.FirstStep, then Var.SecondStep that uses Var.FirstStep.
Examples
- Lookup a rate once:
Var.USADiscount = Rate("Discount", Input.Quote.IssueAge, 1)(conceptually; define the variable formula as the right-hand side). - Data sheet cell:
Var.PlanName = DataSheet("Plans", 1, "Plan"). - Reused intermediate:
Var.NetPremium = Input.Quote.GrossPremium * (1 - Input.Quote.CommissionPct).
User Guides › Matrix Forge
| ← Previous: Formula syntax | Next: Output matrices → |