Formula Syntax
User Guides › Matrix Forge
| ← Previous: Matrix Forge | Next: Variables → |
Formula syntax
Formulas in the calc engine are C#-like expressions. They have access to form/flow inputs, rates, data sheets, the current row index, previous row values, and variables/matrices you define. Unqualified dotted paths (e.g. Quote.Amount) are treated as Input.Quote.Amount.
Referencing form and flow data (Input)
Input— The root object for all inputs to the calc engine (form fields, flow data, and any data schema fields available at this step).- Use dotted paths:
Input.Quote.FaceAmount,Input.Insured.DOB, etc. Names must match the data schema / form field names. - In the UI, the Form and Rates tabs in the calc engine sidebar show which inputs are available; the Ancestry list shows data from upstream steps.
Rates
Rate(sheetName, age, duration)— Returns a rate value from the selected rate file.sheetNameis the name of the rate sheet (e.g. from the flow’s Assets > Rates).ageanddurationare integers (or values that convert to int).RateTableName— The name of the rate table in use (e.g."default"). Used by the engine to resolveRate(...).
Example: Rate("CSO", Input.Quote.IssueAge, 10) for a 10-year duration at issue age.
Data sheets
Data sheets (Assets > Data Sheets) are CSV/XLSX files ingested and queryable in formulas:
DataSheet(dataSheetName, row, col)row: 1-based row index.col: 1-based column index or column name (string).- Example:
DataSheet("MySheet", 10, 3)orDataSheet("MySheet", 10, "Plan").
DataSheetLookup(dataSheetName, keyColumn, keyValue, returnCol)- Looks up a row where
keyColumnequalskeyValue, then returns the cell inreturnCol(column name or 1-based index). - Example:
DataSheetLookup("orders", "invoice_number", "SI-51539", "address").
- Looks up a row where
Row number in matrix calculations
Inside output matrix column formulas, the engine evaluates one row at a time:
RowNum— 1-based index of the current row being evaluated (integer). Use it to index into other matrices or to branch (e.g.RowNum == 1 ? 0 : ...).PreviousRow— Dictionary of the previous row’s column values (same matrix). Useful for recurrence: e.g.PreviousRow["Balance"] * 1.02.Col— The current row’s column values (same matrix). Reference other columns in the same row:Col.NSP,Col.Premium.
Example: Matrix("ParIllustration").Rows[RowNum - 1]["TotalCSV"] — value from another matrix at the same logical row (0-based index).
Accessing other matrices
Matrix("MatrixName")— Returns the computed matrix by name. Each matrix has aRowslist; each row is a dictionary of column name → value.Matrix("Name").Rows[RowNum - 1]["ColumnName"]— Value from another matrix at the current row (0-based index intoRows).- You can use LINQ-style expressions on
Matrix("Name").Rows(e.g..Where(...).Select(...).Sum()) since the engine runs C#.
Variables and context
Var.VariableName— Reference a Variable (pre-calc) by name. Variables are evaluated before matrices.Context— Dictionary of context values available during evaluation.
Math and conversion
- Standard C# Math and Convert APIs are available. For reference:
- Common use:
Math.Round(x, 2),Convert.ToDouble(val),Math.Min(a, b),Math.Max(a, b). - The engine also provides:
round(value, decimals),min(a, b),max(a, b).
Range and aggregators
Range(...)— Builds a list of double values from a row or from context (by column names or prefix + numeric range). Used with aggregators.RangeSum(values),RangeMin(values),RangeMax(values),RangeAvg(values)— Aggregate a sequence of numbers (e.g. fromRange(...)or from a matrix column).IRR(...)— Internal rate of return (e.g. from a list of cashflows or a matrix column).
Reserved / special names
Identifiers that are not prefixed with Input. are treated as Input. when they start a dotted path, except: Var., Col., PreviousRow, Math., Convert., DateTime., Rate, Matrix, Context, RowNum, RateTableName, MatrixLookup, RangeSum, RangeMin, RangeMax, RangeAvg, and string functions like LEFT, RIGHT, LEN.
User Guides › Matrix Forge
| ← Previous: Matrix Forge | Next: Variables → |