# Sheets formula functions — gap analysis & implementation plan
Status: **Phases 0, 1A, 1B, 2 and 3 done** (Phase 3: 2026-09-17); Phase 4
(`LET`/`LAMBDA`) is next. Written 2026-09-15. Compares the ArozOS Office Sheets formula
engine ([`formula.js`](formula.js)) with the
[Google Sheets function list](https://support.google.com/docs/table/25273?hl=en).
## Where we are
| | At planning | Now |
|---|---|---|
| Functions in Google's list (unique names) | 515 | 515 |
| Implemented in Sheets | 37 | **368** (+9 Excel-only: `XMATCH` `NUMBERVALUE` `TEXTBEFORE` `TEXTAFTER` `TAKE` `DROP` `EXPAND` `TEXTSPLIT` `SINGLE`) |
| Missing | 478 | **147** (Phases 4-5 and not planned) |
Coverage by Google category now:
| Category | Google | Have | Missing |
|---|---|---|---|
| Statistical | 136 | 68 | 68 |
| Math | 84 | 77 | 7 |
| Financial | 50 | 27 | 23 |
| Engineering | 47 | 19 | 28 |
| Text | 41 | 41 | 0 |
| Array | 29 | 23 | 6 |
| Date | 26 | 26 | 0 |
| Info | 18 | 18 | 0 |
| Lookup | 17 | 16 | 1 |
| Operator | 17 | 17 | 0 |
| Logical | 13 | 11 | 2 |
| Database | 12 | 12 | 0 |
| Web | 8 | 3 | 5 |
| Google | 7 | 1 | 6 |
| Parser | 6 | 6 | 0 |
| Filter | 4 | 4 | 0 |
| AI | 1 | 0 | 1 |
(Google lists `UNIQUE` under both Operator and Filter, hence 516 rows for
515 names.) What remains is `LET`/`LAMBDA` and its helpers (Phase 4), distributions,
bond maths and complex numbers (Phase 5), and the handful that need a server
or Google (not planned).
### How it was built and tested
- The engine ([`formula.js`](formula.js)) dispatches through a registry;
functions live in `formula_fn_*.js` modules (see the Office README,
"Sheets formula engine", for the helper API).
- [`test_formula_fns.js`](test_formula_fns.js): 774 checks taken from
Microsoft's documented examples (arithmetic cross-checked in Python); it
fails if any registered function lacks a test.
- [`test_golden.js`](test_golden.js) + `TestGoldenDump`
([`mod/office/xlsx_golden_test.go`](../../../mod/office/xlsx_golden_test.go)):
recalculates every formula of real Excel/Google files and compares with
the values those apps stored. The Helpdesk export: 52,111 formulas, 0
differences. Add more fixtures from real workbooks as they come up.
### What the numbers hid (at planning time)
Most of the 478 are cheap scalar functions, but a handful of *engine*
features gate the functions people actually use. Those come first:
1. **Excel name prefixes — an existing bug.** Excel stores functions newer
than the 2007 file format with a prefix: `_xlfn.IFS(...)`,
`_xlfn.IFNA(...)`, `_xlfn.CONCAT(...)`, `_xlfn.XLOOKUP(...)`,
`_xlfn._xlws.FILTER(...)`, and LAMBDA parameters as `_xlpm.x`. Nothing in
`mod/office` or `formula.js` strips or writes these, so `IFS`/`IFNA`/
`CONCAT` already show `#NAME?` in workbooks Excel saved.
2. **Criteria matching** (`">5"`, `"<>"`, `"a*"`, `"~*"`) — shared by every
`*IF`/`*IFS` function and the `D*` database family.
3. **Calling-cell context** — `ROW()`, `COLUMN()`, `ISFORMULA`, relative
`INDIRECT`/`OFFSET` need to know which cell is being evaluated.
4. **References as values** — `INDEX`/`OFFSET`/`INDIRECT` return *references*
(`SUM(A1:INDEX(...))`), not just values.
5. **Spilling** — `FILTER`, `SORT`, `UNIQUE`, `SEQUENCE`, `SPLIT`… return
arrays that fill neighbouring cells. Today a range outside an array
context is `#VALUE!`.
6. **Names** — workbook defined names (`Dept`, `Tech` in the Helpdesk
reference file), `LET`, `LAMBDA`.
7. **Result formats** — Sheets shows `=DATE(2026,9,15)` as a date and
`=TO_PERCENT(0.2)` as `20%`; our cells show the serial number unless the
user formats them.
## Phase 0 — Foundations (engine work, few new functions) — done
Do these before adding functions in bulk; everything after depends on them.
Shipped as planned, with two differences: functions register from
`formula_fn_.js` files next to `formula.js` rather than a
`sheets/formula/` folder, and golden fixtures are not committed (real
workbooks carry private data) — the dump/compare tools take any folder.
Help UI on top of the registry metadata (`syntax`, `cat`) is still to do.
- **Function registry.** Replace the `call()` switch with a table:
`{name, min, max, category, syntax, lazy?, array?, fn}`. Arity errors,
aliases (`CONCATENATE`→`CONCAT`, `MODE`→`MODE.SNGL`) and the function list
shown in help/docs all come from it, and `test_formula.js` can assert that
every registered function has at least one test. Split functions into
modules under `sheets/formula/` (`fn_text.js`, `fn_math.js`, …) that
register into the table; each file must still load both from a `