---
name: tables
description: "Build and update typed tables for expenses, comparisons, budgets, and linked schedules. Edit rows, transpose views, and check formulas and totals."
metadata:
  version: "1.4.0"
  title: "Tables"
  intent: "use"
  areas: "Tables"
---

# Tables

Use a table when people need to compare rows or calculate totals. For example, track each trip expense as a row with an amount and a payer, or compare options/periods side by side in transposed layout.

Use the connected Space and read its current state before editing. For a new remote connection, use https://app.holvor.com/mcp with Streamable HTTP and OAuth. For browser access or help choosing a Space, follow the [coordination playbook](https://app.holvor.com/skills/household-coordination/SKILL.md). For MCP writes, pass the snapshot’s latest sequence as based_on_version and an idempotency_key for the operation.

1. Open **Tables**, then select the table. If you need a new one, choose **New table** and define columns for the values you want to compare. On MCP, inspect `snapshot.tables` first, then use `upsert_table` with a name, optional `key` handle, optional `layout: "rows" | "transposed"`, and typed columns. Creating a table requires `name` and `columns`. To change only the layout of an existing table, call `upsert_table` with `table_id`, `layout`, `based_on_version`, and `idempotency_key`. Omit `name`, `columns`, `inputs`, and `summaries` to keep them. Pass `inputs: []` or `summaries: []` to clear that list.
2. In the browser, edit the cell where its column and row meet (or toggle `[data-cua-action="toggle-table-layout"]` to flip between standard rows and transposed side-by-side columns). In the standard layout, fill in the inline new row and choose **Save new row**. In transposed view, **Add entry** starts another record across the top and **Save entry** saves it. **Add field** adds a comparison field down the left. On MCP, use `upsert_table_rows` with the existing table ID. For edits, keep the existing row ID and column keys so you change the intended record.
3. Check the saved row and any calculated totals. If a formula fails validation, use the returned diagnostics to correct it before writing again.

## Define the columns

Pass a `columns` array to `upsert_table`. Give each column a stable `key` in snake_case, a human-readable `label`, and a `type`. For example:

```json
{
  "columns": [
    {"key": "expense", "label": "Expense", "type": "text"},
    {"key": "amount_due", "label": "Amount due", "type": "currency", "currency": "USD", "rollup": "sum"},
    {"key": "status", "label": "Status", "type": "select", "options": ["Open", "Paid"]}
  ],
  "rows": [{"cells": {"expense": "Cabin", "amount_due": 120, "status": "Open"}}]
}
```

Supported types are `text`, `number`, `currency`, `percent`, `boolean`, `date`, `select`, and `member`. Optional fields are `options` for select choices, `currency` for the currency code, `formula` for a per-row calculation, `rollup` for a column total, `required` (boolean), and `width` (`sm`, `md`, or `lg`). Refer to a column by its key in row cells and formulas. If validation points to `columns[0].name`, put the heading in `label` and retry.

## Formulas and row values

- **Row shape & column types:**
  - In `upsert_table` and `upsert_table_rows`, wrap values inside `cells`: `rows: [{ row_id?: "row_...", cells: { item: "Cabin", amount: 1860, settled: true } }]`.
  - `type: "member"` accepts any person's display name string (joined or pre-join); `type: "select"` validates against `options: [...] `.
- **Column formulas, top Totals row, & cell overrides (never `B4` cell coordinates):**
  - Shared column `formula` uses bare `snake_case` sibling column keys (never prefix with `=`), operators `+ - * / % == != > >= < <= && || !` + `cond ? a : b`, and pure row functions `if(cond, then, else)`, `round(x, digits?)`, `floor(x)`, `ceil(x)`, `abs(x)`, `min(a, b, ...)`, `max(a, b, ...)`, `pow(base, exp)`, `coalesce(x, fallback)`, `concat(a, b, ...)`, `lookup(tables.<table_key>, "match_col", value, "target_col")`, and `what_if(...)`. A column may still be named `tables` or `prev`: a bare `tables` or `prev` reads that column, while `prev.<column>` and `tables.<table_key>...` stay namespace references.
  - **Row-to-row lag (`prev.<col>`):** Reference the prior active row's value via `prev.<col>` (`null` on row 1; e.g. `coalesce(prev.balance, inputs.budget) - amount` or `prev.revenue * (1 + growth)`). Seed base-period actuals on a formula column via a scalar cell override on row 1.
  - **Table-wide assumptions (`inputs`):** Define named scalar parameters in `inputs`, e.g. `{key:"tax_rate", label:"Tax rate", type:"percent", value:0.0825}`. Reference via `inputs.tax_rate`. Use `upsert_table_input` to add or edit one assumption without resending the others. Pass its existing `key` so the formula reference stays stable:

```json
{"table_id":"tbl_...","key":"tax_rate","label":"Tax rate","type":"percent","value":0.0825}
```

Use `update_table_inputs` only to change values of assumptions that already exist. If it reports an unknown key, define that assumption with `upsert_table_input`.
  - **Summary KPIs (`summaries`):** Pass `summaries: [{ key, label, type, formula }]` on `upsert_table` to compute table-level KPIs from row vectors (`sum(rows.<col>)`, `avg(rows.<col>)`, `min(rows.<col>)`, `max(rows.<col>)`, `count(rows.<col>?)`, `sum_if(rows.<col>, predicate)`, `count_if(rows.<col>, predicate)`), `inputs.<key>`, sibling summary keys, and `tables.<key>.*`.
  - **Cross-table links (`tables.<key>.*` & `lookup`):** Each table exposes a `snake_case` `key` (auto-slugified from `name` or passed explicitly on `upsert_table`). Reference upstream tables via `tables.<key>.rollups.<col>`, `tables.<key>.summaries.<sum_key>`, `tables.<key>.inputs.<input_key>`, or `lookup(tables.<key>, "match_col", match_expr, "target_col")`. When creating multiple linked tables in `append_events`, order upstream tables before downstream tables.
  - **Scenario & sensitivity sweeps (`what_if`):** `what_if(tables.<target>.summaries.<out_key>, tables.<up>.inputs.<param>, val_expr [, tables.<up2>.inputs.<param2>, val_expr2, ...])` re-evaluates an upstream summary or rollup under 1 to 4 simultaneous input/summary/rollup overrides (up to 9 arguments total). Any structural edit to the upstream model automatically propagates into every sensitivity cell.
  - **Transposed layout (`layout: "transposed"`):** Set `layout: "transposed"` (or choose **Transpose** in the browser) when comparing options or time periods side by side. Embed live tables in Research Notes (`upsert_fact` with `doc_mode: true`) on a standalone line via `@table[<key_or_id>]{view="full"}` (`"full" | "summary" | "rows" | "transposed"`).
  - **Top Totals row (`rollup`):** `"sum" | "avg" | "min" | "max" | "count" | "checked" | "unchecked"` on columns 1+ (leave column 0 unset).
  - **Per-cell scalar overrides:** Pass scalar overrides via `upsert_table_rows` (`null` resets to `fx`). In the browser, click `td[data-cua-col-key="<col_key>"]` and click `[data-cua-action="override-cell"]` (or `[data-cua-action="reset-cell-override"]`).

For a budget or comparison that already lives in a spreadsheet, use [Google Sheets or CSV sync](https://app.holvor.com/skills/cua-sync-gsheets/SKILL.md).
