Every workbook table is a table of the data model. A relationship links two tables with one key column on each side:
A key with no match, or a blank key, reads blank. A duplicate key on the one side shows #VALUE! at the pivot.
fromis the many side, the foreign key. Manyfromrows can have the same key.tois the one side, the key. Each non-blank key is unique in its column.
The names follow the modelRelationship element that Excel writes in its XLSX files.


{ })), { ], }, { ], }, ], }, ],};
});// The snapshot now holds `workbook.dataModel.relationships`.Data model panel
In the ribbon, Data › Data Tools › Manage Data Model (its button is labeled Data Model) and Relationships open the data model panel. Data Model appears when the workbook has a table, and Relationships when it has two. The panel loads on first use.
- Tables lists each table with its column and data-row counts.
- Relationships lists each relationship as
Data[Key] → Lookup[Key]with its key status, and Edit and Delete buttons. - The form picks the data table and its key column (the many side), and the lookup table and its key column (the one side).
Each save and delete is one undo step. As Excel's Create Relationship dialog does, the panel does not keep a relationship whose lookup keys repeat or whose key types differ; it shows the reason instead. The API keeps such a relationship, because cells can change later.
Rules
A relationship refers to tables and columns by their stable IDs, so renames, column moves and row or column edits keep it. A new relationship is refused when:
- a table or a column does not exist,
- both sides are the same table,
- another relationship already joins the same two tables,
- the relationships would form a cycle when direction is ignored. So two related tables always have exactly one path between them.
Removing a table or a column keeps the relationships that refer to it, and undo restores a working model.
A query refresh keeps the ID and column IDs of its output table, so relationships to that table stay. Pivots over related tables update in the same undo step as the refresh.
Undo and collaboration
setRelationship and removeRelationship are document operations. Each change is one undo step, and it is saved and synchronized like other workbook metadata. Two concurrent relationship changes conflict, because the rules apply to the whole model. A pending relationship also conflicts with a concurrent change to one of its tables, or with the removal of a sheet.
| Store method | Result |
|---|---|
get | Copies of the saved relationships |
set | Inserts it, or replaces the one with its ID |
remove | Removes it |
get | Whether the keys resolve, checked from the current cells |
Key checks
The full engine checks the key values each time getRelationshipStatus is called. Keys match as pivot group keys do: numbers by value, and text without case. A blank key matches nothing.
| Status | Meaning |
|---|---|
ok | Every non-blank one-side key is unique. unmatched counts the non-blank many-side keys that no one-side row holds. |
missing, missing | A table or a column was removed. |
type | The key at row on side from or to is a boolean, an error on the one side, or a number among text keys (or text among numbers). |
duplicate | Two one-side rows hold equal keys. rows are their data-row offsets. |
unavailable | The default engine checks no keys, or no relationship has this ID. |
Pivots across related tables
A model source names a base table (the many side) and the fields to read. Each field is a table and column ID. A field's table must be the base table or a table the base reaches through many-to-one relationships. Field i in rows, columns, values and filters is model.fields[i].
model: { ], }, },});The result equals a pivot over the table you get by looking up each related column for every base row:
| Case | Related value |
|---|---|
| The key matches one row | That row's cell |
| The key matches no row, or is blank | Blank |
| The many-side key is an error | That error |
A duplicate one-side key or a key type mismatch shows #VALUE! at the anchor. A missing table, column or relationship shows #REF!. The default engine keeps and syncs model pivots but does not compute them. XLSX export keeps them in Sheetwrite metadata, because Excel needs its own data-model binary for a model pivot. It also writes their current output as cells, so Excel shows the values.
In the PivotTable Fields panel, a pivot over a table shows a Related section for each table that its table reaches through relationships. The actions menu of a related column adds it to an area. A table source then becomes a model source whose first fields are the table's columns, so the fields in use keep their indices. This is one undo step. The panel names a related field with its table, for example Customers › Region.
Measures
A measure is a named formula over model columns, saved in workbook.dataModel.measures. A pivot with a model source shows it as a value field, { measure: id }. As in Excel, each value cell, subtotal and grand total calculates the formula again over the base rows that its row items, column items and report filters select. So a total of =SUM(Orders[Amount])/COUNT(Orders[Amount]) is the mean of all its rows, not the sum of the means above it (Measures in Power Pivot, filter context).
{ }, }, ],}); model: { }, },});- Names. Every measure belongs to a home table. Measure names are unique ignoring case and differ from the column names of the home table, following the DAX naming requirements. The default header of a measure value is the measure name.
- Formulas. A measure uses the formula language of cells. Its references are qualified data columns of any model table, such as
Orders[Amount], and other measures by name, such as[Mean Amount](column and measure references). Cell and range references, defined names and the#All,#Headers,#Totalsand@sections are refused, because a measure has no cell position. - Related tables. Columns of the base table see the rows of the cell. Another table sees its rows that match the cell's row items, column items and report filters on the fields it reaches through many-to-one relationships, including its own columns. Fields it cannot reach put no condition on it, so filters flow from the one side to the many side only, as with a single cross-filter direction. With orders related to customers,
=SUM(Customers[Credit])changes with a customer region on rows but shows the same value in every order month column. - CALCULATE.
=CALCULATE(expression, filter, …)evaluates its expression in a changed filter context, following CALCULATE. A filter is either a comparison of one model column with a value, such asCustomers[Region]="West"orOrders[Month]>=3(with=,<>,<,<=,>or>=), which replaces the row items, column items and report filter on that column, orALL(Table[Column]), which removes them, as ALL does. Filters on other columns stay, and a comparison filters a table only when the table reaches the compared column through many-to-one relationships. The value of a comparison is evaluated once and may not read columns. For example,=SUM(Orders[Amount])/CALCULATE(SUM(Orders[Amount]), ALL(Customers[Region]))is each region's share of its month. Other filters, such asALL(Table),FILTERor a comparison of two columns, and aCALCULATEinside another show#VALUE!. Excel has no worksheet functions namedCALCULATEorALL, so a cell formula that uses them shows#NAME?. - Errors. A formula that does not parse shows
#NAME?in its value cells, a missing table or column or an unknown measure name shows#REF!, and an unsupported reference or measures that refer to each other in a cycle show#VALUE!. A formula that returns more than one value also shows#VALUE!. A pivot whose measure was removed shows#REF!at its anchor until undo restores the measure. A cell with no rows of the base table stays blank when the measure reads base-table columns. - Renames. Renaming a table or one of its columns with
updateTablerewrites the measure formulas that name it, as Excel updates formulas when a table is renamed. Renaming a measure withsetMeasurerewrites the[Name]references to it. The rewrite is part of that change, so one undo step reverses both. A measure change made while another collaborator renames a table or column conflicts, and the client reloads the shared document, so both end with the new names. - GETPIVOTDATA reads a measure value by the measure name, like any value field.
- Engines. The full engine keeps no measure results between recomputes.
| Store method | Result |
|---|---|
get | Copies of the saved measures |
set | Inserts it, or replaces the one with its ID |
remove | Removes it |
get | missing when the home table is gone, syntax when the formula does not parse, otherwise ok; unavailable for an unknown ID. Checked on every engine; reference errors show in the pivot cells. |
setMeasure and removeMeasure are document operations: each change is one undo step, and it is saved, synchronized and restored from version history. Two concurrent data model changes conflict. XLSX export keeps measures and the pivots that use them in Sheetwrite metadata, because Excel keeps measures in its data model part.
Data › Data Tools › Measures opens the Measures panel once the workbook has a table. It lists the measures under their home tables, with a note when a formula does not parse or its table is gone. The form below names a measure, picks its home table and takes its formula; Edit loads a measure into the form, and Remove deletes it. Each save and removal is one undo step. In the PivotTable field list, a pivot over a table or the data model lists the measures it does not show yet under Measures: Table, marked fx, with Add to Values, as Excel's Field List lists measures under their home table. Adding a measure to a pivot over one table makes its source a model source with the same fields.
XLSX files
Relationships and pivots over related tables are saved in Sheetwrite metadata, so a Sheetwrite file opens with them again. Import also reads the active relationships of an Excel data model between worksheet tables, by table and column name, and reports the relationships it cannot use. Sheetwrite does not write an Excel data model, so Excel opens the file without relationships. A model pivot, measures included, is written as the cells of its current output with its number formats, so Excel shows its values without a pivot; Sheetwrite reopens it as a live pivot. See Kept parts and round trips.
function initSheetwrite(options?: InitSheetwriteOptions): Promise<void>Load one WASM engine and install add-ons before createGrid.API referenceclass SheetwriteStoreStable public facade and the sole transaction, epoch, policy, and event barrier.API referenceinterface WorkbookSnapshotSchema-versioned serializable workbook document.API referenceWorkbookSnapshot.schemaVersion: 1Format version of the snapshot; always 1.API referenceWorkbookSnapshot.workbook: { activeSheet: SheetId; namedRanges?: NamedRangeSnapshot[]; xlsxSource?: XlsxSourceSnapshot; calculation?: CalculationSettings; dataModel?: DataModel; queries?: SavedQuery[]; externalLinks?: ExternalLink[]; }Workbook-wide state: the active sheet, named ranges, and kept XLSX parts.API referenceactiveSheet: stringStable ID of the sheet shown when the workbook opens.API referenceWorkbookSnapshot.sheets: SheetSnapshot[]Every sheet of the workbook, worksheets and dashboards alike.API referenceSheetSnapshot.id: stringStable identifier, unique within the workbook and used by every cell address.API referenceSheetSnapshot.name: stringUser-facing sheet name shown in tabs and workbook exports.API referenceSheetSnapshot.order: numberZero-based position of the sheet's tab.API referenceSheetSnapshot.rowCount: numberRows in the sheet, empty rows after the last stored cell included.API referenceSheetSnapshot.columns: Column[]Keys are stable, unique document column identities as well as datasource keys.API referenceArray<string>.map<{ key: string; header: string; width: number; type: "text"; }>(callbackfn: (value: string, index: number, array: string[]) => { key: string; header: string; width: number; type: "text"; }, thisArg?: any): { key: string; header: string; width: number; type: "text"; }[]Calls a defined callback function on each element of an array, and returns an array that contains the results.key: stringColumn.key: stringNon-empty key, unique within the sheet, used to map input and datasource values.API referenceColumn.header: stringSchema label used by table exports and data-grid presentation headers.API referenceColumn.width: numberUnzoomed column width in CSS pixels.API referenceColumn.type: CellFormatControls cell input parsing and default value formatting for this column.API referencetype const = "text"SheetSnapshot.tables?: WorkbookTable[] | undefinedWorkbook tables anchored on this sheet.API referenceWorkbookTable.id: stringStable ID, unique in the workbook; it stays the same when the table is renamed.API referenceWorkbookTable.name: stringWorkbook-global, case-insensitively unique structured-reference name.API referenceWorkbookTable.range: RangeInclusive table rectangle on one stable sheet ID.API referenceRange.sheet: stringStable ID of the sheet the range is on.API referenceRange.start: { row: number; col: number; }Zero-based row and column of one corner cell, included in the range.API referencerow: numberRow index, counting from 0 at the sheet's first row.API referencecol: numberColumn index, counting from 0 at the sheet's first column.API referenceRange.end: { row: number; col: number; }Zero-based row and column of the opposite corner cell, also included.API referenceWorkbookTable.columns: WorkbookTableColumn[]Ordered stable columns; length is exactly the table rectangle width.API referenceWorkbookTableColumn.id: stringStable ID, unique within the table; it stays the same when the column is renamed.API referenceWorkbookTableColumn.name: stringCase-insensitively unique within the table.API referenceWorkbookTable.headerRow: booleanWhether the first range row is the structured-reference header row.API referenceWorkbookTable.totalsRow: booleanWhether the last range row is the structured-reference totals row.API referenceSheetSnapshot.cells: CellBlock[]The sheet's non-empty cells, in rectangular blocks.API referenceconst store: SheetwriteStoreAPI referenceSheetwriteStore.fromSnapshot(input: unknown, options?: SheetwriteStoreOptions): SheetwriteStoreCreates a store from a saved snapshot, validating it first; an invalid one throws.API referenceconst snapshot: WorkbookSnapshotAPI referenceSheetwriteStore.setRelationship(relationship: TableRelationship): ApplyTransactionResultInsert a relationship, or replace the one with its ID. Both columns must exist, at most one relationship may join two tables, and relationships must not form a cycle; otherwise the result is a no-op.API referenceTableRelationship.id: stringStable identity, unique in the workbook.API referenceTableRelationship.from: TableColumnRefMany side: the foreign-key column.API referenceTableColumnRef.table: stringStable WorkbookTable.id.API referenceTableColumnRef.column: stringStable WorkbookTableColumn.id.API referenceTableRelationship.to: TableColumnRefOne side: the key column, whose non-blank values must be unique.API referenceconst saved: TableRelationship[]API referenceSheetwriteStore.exportSnapshot(): WorkbookSnapshotExport the whole workbook document. The export is complete, authoritative, deterministic.API referencedataModel?: DataModel | undefinedRelationships between workbook tables; omitted when there are none.API referenceDataModel.relationships: TableRelationship[] | undefinedRelationships; at most one joins a pair of tables, and they form no cycle.API referenceArray<TableRelationship>.length: numberGets or sets the length of the array. This is a number one higher than the highest index in the array.var Error: new (message?: string, options?: ErrorOptions) => ErrorSheetwriteStore.dispose(): voidFrees the engine memory this store holds; do not use the store afterwards.API referenceconst grid: GridAPI referenceGrid.setPivot(pivot: PivotDefinition, sheet?: SheetId): ApplyTransactionResultInsert or replace a pivot as one undo entry. sheet defaults to the sheet that holds the pivot's ID, then to the active sheet. The pivot's savedOutput is removed, because it does not match a changed definition.API referencePivotDefinition.id: stringStable identity, unique in the workbook.API referencePivotDefinition.name: stringUser-facing caption.API referencePivotDefinition.source: PivotSourceData the pivot summarizes.API referencemodel: { table: WorkbookTableId; fields: TableColumnRef[]; }table: stringHome table, used to organize the field list.API referencefields: TableColumnRef[]For changed: the sheet fields that differ, such as name, rowCount or merges.API referencePivotDefinition.anchor: { row: number; col: number; }Top-left output cell on the owning sheet. Deleting the anchor's row or column keeps the pivot and moves the anchor to the first surviving cell at the deletion position.API referencePivotDefinition.rows: number[]Source field indices that group the output rows, outermost first.API referencePivotDefinition.columns: number[]Source field indices that group the output columns, outermost first.API referencePivotDefinition.values: PivotValueField[]Aggregated fields, in output order.API referencefield: numberThe table column whose values the slicer lists.API referenceaggregation: PivotAggregationAPI referenceGrid.applyTransaction(transaction: GridTransaction): ApplyTransactionResultApply patches as one change the user can undo. No-op when read-only. Use Store.applyTransaction only for low-level writes that intentionally bypass Grid history and policy.API referenceGridTransaction.patches: DocumentOp[]Document operations, applied in order as one undo step.API referenceop: "setMeasure"The comparison. beginsWith, endsWith, contains and notContains take text; the others take a number (a date is its serial) or text.API referencemeasure: MeasureMeasure.id of a measure of the workbook's data model.API referenceMeasure.id: stringStable identity, unique in the workbook.API referenceMeasure.name: stringCaption, unique among measures ignoring case.API referenceMeasure.table: stringHome table, used to organize the field list.API referenceMeasure.formula: stringFormula with its leading = and qualified model-column references.API referencemeasure: stringMeasure.id of a measure of the workbook's data model.API reference