Skip to content

PivotTables: GETPIVOTDATA, Generate GetPivotData, and the PivotTable Analyze/Design tabs - #1189

Open
Herr-Enklo wants to merge 2 commits into
storytold:mainfrom
Herr-Enklo:feat/getpivotdata
Open

Herr-Enklo wants to merge 2 commits into
storytold:mainfrom
Herr-Enklo:feat/getpivotdata

Conversation

@Herr-Enklo

Copy link
Copy Markdown

Adds Excel's GETPIVOTDATA, Generate GetPivotData, and the PivotTable Analyze / PivotTable Design contextual tabs (gaps.md §8).

PivotTable Analyze and PivotTable Design tabs

  • Both tabs appear while the active cell is in a PivotTable. When the cell leaves the PivotTable, the ribbon returns to Home.
  • The groups follow Excel 365 in its order:
    • Analyze: PivotTable, Active Field, Group, Filter, Data, Actions, Calculations, Tools, Show.
    • Design: Layout, PivotTable Style Options, PivotTable Styles.
  • The existing pivot commands are wired in. Active Field now reads the field of the active cell.
  • Controls GridCraft can't run yet (timelines, calculated items, grouping dialogs, OLAP, Relationships…) stay visible but disabled, with the reason on hover. Each group is its own function in ribbon/pivot_tabs.rs, so follow-up work can wire them in directly.
  • New commands: pivot.clearAll (empties the PivotTable and keeps it, as Excel does; the old Clear All deleted it), pivot.clearFilters, pivot.showFieldList.
  • New dialogs: Value Field Settings and Change PivotTable Data Source.
  • German labels were observed in German Excel 365 (PivotTable-Analyse, Entwurf, Aktives Feld, Einblenden…).
  • Key tips: JT and JY, only while the tabs are shown, so Table Design's JT still works.

GETPIVOTDATA

The rules below were checked against Excel 365 on synthetic workbooks:

  • The data field is named by its caption or its source field, case-insensitive.
  • pivot_table may be any cell or range in the report.
  • Pairs may name row, column or report-filter fields.
  • An omitted field means its total. If that total isn't shown, the one item the other pairs leave is used.
  • Hidden, filtered or collapsed items, totals that are turned off, and ambiguous pairs return #REF!.
  • Empty cells in a cross-tab return 0. Show Values As results come back as displayed.

How it is built:

  • When the engine writes a report, it also records what each line and data column stands for, as a runtime index on the PivotTable (model::PivotReport, not saved).
  • calc evaluates GETPIVOTDATA from that index without depending on the engine, and recalculates on refresh and on edits inside the report.
  • PivotTables from files are indexed on open when their cells match the recomputed report.
  • There is no _xlfn. prefix; the formula round-trips through XLSX.
  • Known gaps, documented in function-parity.md: Excel's "Values" pseudo-field pair, and arrays of items.

Generate GetPivotData

  • An app setting, on by default.
  • It appears in PivotTable Analyze › Options ▾ and in File › Options › Formulas › Use GetPivotData functions for PivotTable references.
  • While you type a formula, clicking, dragging back onto, or arrowing onto a PivotTable value inserts GETPIVOTDATA("Sum of Sales",$A$3,"Region","East"), as Excel does.
  • The formula adds the sheet name when the pivot is on another sheet, writes date items as DATE(), and follows the formula locale's separators.

Tests

  • crates/engine/tests/getpivotdata.rs (11):
    • grand total, row and column items, subtotals
    • unknown, filtered and collapsed items
    • report filters, dates and numbers
    • data field by caption and by source name
    • after refresh and after a source edit
    • XLSX round trip, and a stale file
  • One more engine test generates the formula for every value cell of several layouts and checks that each one reads back its own cell.
  • Model and calc unit tests, and an XLSX prefix test.
  • egui_kittest UI tests for the tabs, key tips and point mode.
  • cargo xtask ci: all 8 steps pass (1627 tests).

🤖 Generated with Claude Code

Herr-Enklo and others added 2 commits October 13, 2026 23:53
The ribbon now shows Excel's two PivotTable tabs while the active cell is in a
PivotTable report, and goes back to Home when it leaves. Every group follows
Excel 365 in order and control type: Analyze has PivotTable (name, Options),
Active Field, Group, Filter, Data, Actions, Calculations, Tools and Show;
Design has Layout (Subtotals, Grand Totals, Report Layout, Blank Rows),
PivotTable Style Options and the PivotTable Styles gallery. Existing pivot
commands are wired where Excel has them; controls for features GridCraft
doesn't have yet (slicers and timelines for PivotTables, calculated items,
grouping dialogs, OLAP tools, blank rows...) stay visible, disabled, with the
reason on hover. Each group is its own function in ribbon/pivot_tabs.rs, so a
feature can be wired in where its control already sits.

New pieces behind the controls:
- pivot.clearAll and pivot.clearFilters (Actions > Clear): Clear All empties
  the PivotTable but keeps it, as Excel does, instead of deleting it.
- pivot.showFieldList (UI): the Field List toggle hides the Fields pane.
- Value Field Settings and Change PivotTable Data Source dialogs.
- Key tips JT and JY. They are contextual: the matcher switches to a
  contextual tab only while it shows, so Table Design's JT letters keep
  working; xtask keytips accepts contextual tab targets and generates tests
  for the hidden case.
- German labels in German Excel's wording (PivotTable-Analyse, Entwurf, ...),
  checked against the installed German Excel's own labels.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
GETPIVOTDATA(data_field, pivot_table, [field1, item1], ...) reads a value
shown in a PivotTable report, with Excel's semantics, checked against Excel
365 on synthetic PivotTables:
- data_field is a value field's caption or its source field, case ignored;
  pivot_table is any cell or range in the report (#REF! otherwise).
- Pairs name row, column or single-item report filter fields and one of
  their shown items: numbers and dates (serials or DATE) match by value,
  text matches an item's label. Fields left out stand for their total, or
  for the one item the named items leave (Plums sells only in the West).
- Hidden, filtered and collapsed items, totals turned off and ambiguous
  pairs give #REF!; an empty value cell in a cross tab is 0; Show Values As
  results come back as shown.

Layering: the engine, which lays out reports, now records with each report
what every line and data column stands for (model PivotReport, a runtime
cache on the PivotTable that comparisons ignore). calc evaluates
GETPIVOTDATA from that index alone and depends on the report area, so
refreshes (full recalcs) and edits inside the report reach it. Reports of
PivotTables read from files are indexed on open when the recomputed report
matches the cells on the sheet. GETPIVOTDATA has no _xlfn prefix in files.

Generate GetPivotData (PivotTable Analyze > PivotTable > Options, and File
> Options > Formulas > Use GetPivotData functions for PivotTable
references) is an application setting, on by default: clicking, dragging
back to or arrowing onto a PivotTable value while typing a formula inserts
GETPIVOTDATA("Sum of Sales",$A$3,"Region","East") instead of the
reference, with the sheet when the PivotTable is elsewhere and DATE for
date items.

The PivotTable Analyze tab now uses the index too: Active Field shows the
active cell's field, Field Settings opens Value Field Settings, Expand and
Collapse Field and Ungroup act on it, and Select > Values selects the
value cells.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
@Harrison-Booth

Copy link
Copy Markdown
Contributor

Thanks @vangel76 (#290) and @Herr-Enklo (#1189) for both taking this on. I built both heads (dbf9e5a and dbf7dc7, both on 84acf62) and compared them with Excel on 74 GETPIVOTDATA cells: the 10 in the corpus's getpivotdata/field-item-forms.xlsx plus 64 I built in Excel. They cover row and column fields, report filters, totals off, dates and numbers as items, captions, hidden items, several data fields, tabular layout, another sheet and a stale report. Excel's saved value is the reference. This is formula results only; I didn't test the UI work in #1189.

#290 #1189
Opened (run --in) 59 / 74 30 / 74
After pivot.refresh 59 / 74 60 / 74

Why they differ on open: #290 recomputes each pivot from its source when the file opens. #1189 only indexes a pivot if the recomputed report matches the cells on the sheet. GridCraft lays items out in source order and Excel sorts them, so that check fails on most files until a refresh.

Other differences:

Shared, not specific to either PR:

  • Captions: Excel accepts the renamed field and item ("Area", "North Zone"). Both PRs only accept the source names (4 cells).
  • On main, <pageField item="1"> is read as an index into the cache's shared items instead of the field's item list, so a filter showing "north" imports as "south" (5 cells). I can open a separate issue.
  • gridcraft-cli check returns #REF! for every GETPIVOTDATA cell in both PRs, because check_inner doesn't go through DocState::new, where both build the pivot index. Only the 21 cells where Excel also shows #REF! match.

Everything else matched Excel in both: case-insensitive names, data field by caption or source name, items from cells, either field order, dates and numbers as items, hidden items, totals off, filters, Count, Average and % of total, tabular layout, another sheet.

The workbooks and the build script are available if you want them.

🤖 Generated with Claude Code. Reviewed by @Harrison-Booth before posting.

@Herr-Enklo

Copy link
Copy Markdown
Author

Hi @Harrison-Booth , thanks for the detailed testing and feedback. I’ve made targeted local fixes for the pivot issues and checked selected cases, but I haven’t rerun your full 74-case suite, so I can’t claim the same coverage yet.
Could you share the test workbooks and build script you offered? That would help me reproduce your cases and check what still needs fixing. Thanks!

@Harrison-Booth

Copy link
Copy Markdown
Contributor

@Herr-Enklo thanks. I can share the 74 GETPIVOTDATA cases as a small synthetic workbook, plus the steps I used to build your head and compare it with Excel. I'll post it here once I've checked it holds no private data. If you'd rather start now, the 10 cases that differed from Excel are the ones to look at first.

🤖 Generated with Claude Code. Reviewed by @Harrison-Booth before posting.

@Harrison-Booth

Copy link
Copy Markdown
Contributor

@Herr-Enklo the 74 cases are now in the public corpus: https://github.com/Harrison-Booth/gridcraft-corpus/tree/main/excel/getpivotdata. They are the 10 cells in field-item-forms.xlsx plus 10 new workbooks (64 cells) covering row and column fields, report filters, totals off, dates and numbers as items, captions, hidden items, several data fields, a stale report and a tabular pivot on another sheet. They are built in Excel by the corpus generator (tools/excel-oracles/cases.ps1), with Excel's value next to every formula, so gridcraft-cli check compares them directly.

🤖 Generated with Claude Code. Reviewed by @Harrison-Booth before posting.

This branch has not been deployed

No deployments
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants