Function Reference
Formula callbacks receive fx, a set of typed Excel functions. Arguments accept column references (refs.column(...)), other fx results, and plain values. Column ids stay checked by TypeScript inside every function, including fx.call.
This page lists every function. For the operators (.add, .gt, …) and scope rules, see Scope & References.
Where functions can be used
fx is passed to every formula callback:
| Place | Callback | Ranges available |
|---|---|---|
| Formula column, report mode | formula: ({ row, refs, fx }) => … | row.series(id) |
| Formula column, excel-table mode | formula: ({ row, refs, fx }) => … | none |
| Column conditional style | rule.when(({ row, refs, fx }) => …) | none |
| Data validation | validation.custom(({ row, refs, fx }) => …) | none |
| Summary formula | summary.formula(({ column, fx }) => …) | column.cells(), row.cells() |
| Summary conditional style | rule.when(({ cell, fx }) => …) | none |
Every fx function works in every place. Functions that read a range (countIf, sumIf, …) are methods of a range, so they only exist where a range does. Calling row.series(...) in an excel-table formula, a conditional style or a validation rule is a type error: these formulas read one row.
Logic and errors
| Function | Excel | Notes |
|---|---|---|
fx.if(cond, a, b) | IF(cond, a, b) | |
fx.and(...c), fx.or(...c) | AND(...), OR(...) | |
fx.not(c) | NOT(c) | |
fx.ifError(value, fallback) | IFERROR(value, fallback) | fallback for any error (#DIV/0!, #N/A, #VALUE!, …) |
fx.ifNa(value, fallback) | IFNA(value, fallback) | Only #N/A. Excel 2013 and later; written _xlfn.IFNA |
fx.isBlank(value) | ISBLANK(value) | A condition. True for an empty cell, false for empty text |
import { createExcelSchema } from "typed-xlsx";
createExcelSchema<{ revenue: number; units: number; note: string | null }>()
.column("revenue", { accessor: "revenue" })
.column("units", { accessor: "units" })
.column("note", { accessor: "note" })
.column("unitPrice", {
formula: ({ refs, fx }) => fx.ifError(refs.column("revenue").div(refs.column("units")), 0),
})
.column("hasNote", {
formula: ({ refs, fx }) => fx.if(fx.isBlank(refs.column("note")), "no", "yes"),
})
.build();
Math
| Function | Excel | Notes |
|---|---|---|
fx.round(v, d?) | ROUND(v, d) | Half away from zero. d defaults to 0 |
fx.roundUp(v, d?) | ROUNDUP(v, d) | Away from zero |
fx.roundDown(v, d?) | ROUNDDOWN(v, d) | Toward zero |
fx.int(v) | INT(v) | Down to the integer below: INT(-1.5) = -2 |
fx.mod(n, d) | MOD(n, d) | Result has the sign of d |
fx.power(b, e) | POWER(b, e) | |
fx.sqrt(v) | SQRT(v) | |
fx.abs(v) | ABS(v) | |
fx.safeDiv(n, d, …) | IF(d<>0, n/d, …) | See Scope & References |
fx.sum, average, count, min, max | SUM(...), … | Values, or a whole group with refs.group(id) |
fx.countA(...) | COUNTA(...) | Non-empty values, or a whole group |
import { createExcelSchema } from "typed-xlsx";
createExcelSchema<{ minutes: number }>()
.column("minutes", { accessor: "minutes" })
.column("hours", { formula: ({ refs, fx }) => fx.int(refs.column("minutes").div(60)) })
.column("rest", { formula: ({ refs, fx }) => fx.mod(refs.column("minutes"), 60) })
.column("billed", { formula: ({ refs, fx }) => fx.roundUp(refs.column("minutes").div(60), 1) })
.build();
Text
| Function | Excel | Notes |
|---|---|---|
fx.concat(a, ...) | CONCATENATE(a, ...) | Works in every Excel version |
fx.text(v, format) | TEXT(v, format) | format is an Excel number format, e.g. "0.00" |
fx.left(t, n?) | LEFT(t, n) | n defaults to 1 |
fx.right(t, n?) | RIGHT(t, n) | n defaults to 1 |
fx.len(t) | LEN(t) | |
fx.upper(t), fx.lower(t) | UPPER(t), LOWER(t) | |
fx.trim(t) | TRIM(t) | Removes outer spaces and repeated inner spaces |
import { createExcelSchema } from "typed-xlsx";
createExcelSchema<{ firstName: string; lastName: string; amount: number }>()
.column("firstName", { accessor: "firstName" })
.column("lastName", { accessor: "lastName" })
.column("amount", { accessor: "amount" })
.column("initials", {
formula: ({ refs, fx }) =>
fx.upper(fx.concat(fx.left(refs.column("firstName")), fx.left(refs.column("lastName")))),
})
.column("label", {
formula: ({ refs, fx }) =>
fx.concat(fx.trim(refs.column("lastName")), ": ", fx.text(refs.column("amount"), "0.00")),
})
.build();
TEXT formats with the reader's Excel locale (decimal separator, month names).
Dates
Excel stores dates as serial numbers. Give a date result a date format to show it as a date.
| Function | Excel | Notes |
|---|---|---|
fx.date(y, m, d) | DATE(y, m, d) | Months and days past the end roll over |
fx.year(d) | YEAR(d) | |
fx.month(d) | MONTH(d) | 1 to 12 |
fx.day(d) | DAY(d) | 1 to 31 |
fx.eoMonth(d, n) | EOMONTH(d, n) | Last day of the month n months after d |
fx.today() | TODAY() | Volatile: Excel recomputes it every time the file opens |
fx.now() | NOW() | Volatile, like TODAY() |
import { createExcelSchema } from "typed-xlsx";
createExcelSchema<{ invoicedAt: Date }>()
.column("invoicedAt", { accessor: "invoicedAt", format: "yyyy-mm-dd" })
.column("dueAt", {
format: "yyyy-mm-dd",
formula: ({ refs, fx }) => fx.eoMonth(refs.column("invoicedAt"), 1),
})
.column("overdue", {
formula: ({ refs, fx }) => fx.if(fx.today().gt(refs.column("dueAt")), "yes", "no"),
})
.build();
Ranges: counts and criteria
A range is a block of cells in one column. In a report-mode formula column, row.series(id) is the column's cells for the current logical row (see Row Model). In a summary, column.cells() is the column's data cells, and row.cells() inside column.rows(...) is one logical row's cells.
Every range has:
| Method | Excel |
|---|---|
.sum(), .average(), .min(), .max(), .count() | SUM(range), … |
.countA() | COUNTA(range): non-empty cells |
.countBlank() | COUNTBLANK(range): empty cells and empty text |
.countIf(criteria) | COUNTIF(range, criteria) |
.sumIf(criteria) | SUMIF(range, criteria) |
.averageIf(criteria) | AVERAGEIF(range, criteria) |
criteria follows Excel: a value to match ("paid", 0), or text with a comparison (">0", "<>"). To compare with a cell, build the text with fx.concat:
import { createExcelSchema } from "typed-xlsx";
createExcelSchema<{ lines: number[]; threshold: number }>()
.column("line", {
accessor: (row) => row.lines,
summary: (summary) => [
summary.formula(({ column }) => column.cells().countIf(">0")),
summary.formula(({ column }) => column.cells().sumIf("<0")),
],
})
.column("threshold", { accessor: "threshold" })
.column("linesAbove", {
expansion: "single",
formula: ({ row, refs, fx }) =>
row.series("line").countIf(fx.concat(">", refs.column("threshold"))),
})
.build();
In a summary with no data rows there is no range to point at, so these write a constant instead: 0 for the counts and sumIf, empty text for averageIf.
The multi-condition forms (COUNTIFS, SUMIFS, AVERAGEIFS) compare several columns, which only row.series can reach. Write them with fx.call, below.
fx.call: any other Excel function
fx.call(name, ...args) writes any Excel function. Arguments are values, conditions, or ranges; column ids in them stay checked. The result works as a value (.mul(10)) and as a condition (fx.if(fx.call("ISNUMBER", …), …)).
import { createExcelSchema } from "typed-xlsx";
createExcelSchema<{ lines: number[]; status: string[]; code: string }>()
.column("line", {
accessor: (row) => row.lines,
summary: (summary) => [
summary.formula(({ column, fx }) => fx.call("MEDIAN", column.cells())),
summary.formula(({ column, fx }) => fx.call("STDEV.S", column.cells())),
],
})
.column("status", { accessor: (row) => row.status })
.column("code", { accessor: "code" })
.column("paidTotal", {
expansion: "single",
formula: ({ row, fx }) => fx.call("SUMIFS", row.series("line"), row.series("status"), "paid"),
})
.column("numeric", {
formula: ({ refs, fx }) => fx.if(fx.call("ISNUMBER", refs.column("code")), "yes", "no"),
})
.build();
Rules:
- Names are upper-case, as Excel writes them (
"STDEV.S", not"stdev.s"). A lower-case name is a type error, and an invalid name throws when the file is written. - The
_xlfn.prefix. Functions added after Excel 2007 are stored in the file as_xlfn.NAME; without it, Excel shows#NAME?until the cell is edited.fx.calladds the prefix for the functions it knows (STDEV.S,XLOOKUP,TEXTJOIN,IFS,MAXIFS,CONCAT, …). For a newer function it does not know, pass the prefixed name yourself:fx.call("_xlfn.NEWFUNC", …). - No spilling arrays. Functions that return several cells (
FILTER,SORT,UNIQUE,SEQUENCE,LET, …) need array metadata typed-xlsx does not write. They are a type error, and throw at runtime. - No group scopes.
refs.group(...)is not anfx.callargument; use a range or list the columns.
Cached values in excel tables
In excel-table mode, typed-xlsx writes the result next to each formula when it can compute it exactly as Excel does, so the file shows values even before Excel recalculates. It leaves the result for Excel when it is not certain:
fx.today(),fx.now(),fx.text(...)andfx.call(...)- any Excel error, including one caught by
fx.ifError - text conversions of numbers with decimals or from 1E+15 up (
fx.concat("x", 1.5)), and case changes of non-ASCII text - dates before 1 March 1900
- a formula that reads another formula column with no cached value