Repository navigation
Conversation
… base item pivot.valueSettings accepts every Show Values As calculation: % of, % of Parent Row Total, % of Parent Column Total, % of Parent Total, Difference From, % Difference From, % Running Total In, Rank Smallest to Largest and Index, in addition to the existing % of Grand Total, % of Column Total, % of Row Total, Running Total In and Rank Largest to Smallest. The calculations that need one take a base field (a row or column field) and a base item (an item label, "(previous)" or "(next)"); Running Total and Rank now follow the base field instead of always using the first row field. pivot.fields reports the base field and item. XLSX: written and read as showDataAs with baseField and baseItem, and as the x14 pivotShowAs extension for the calculations that showDataAs cannot express.
pivot.group accepts by: range with start, end and interval (Excel's Starting at, Ending at and By), defaulting to the field's smallest and largest numbers in steps of 10. Each range becomes one item captioned "0-9" for whole-number steps or "0-2.5" otherwise; numbers below the start or above the end fall into "<start" and ">end" items, sorted first and last. Bounds must be finite with start no greater than end, the step positive, and the grouping is limited to 100,000 ranges. by: none removes the grouping, and a change of grouping clears the field's item selection. pivot.list and pivot.fields report the range; the field menu in the PivotTable Fields pane gains Group by Ranges of 10. XLSX: written as a fieldGroup on the base cache field with rangePr startNum, endNum and groupInterval and the group items, and read back; a range without a usable width is ungrouped with a warning.
New commands set a filter rule on a row or column field: - pivot.labelFilter compares each item's caption: equals, does not equal, begins with, ends with, contains (and their negations), greater than, less than, between and not between. The text comparisons take * and ? wildcards; numbers compare as numbers; case does not matter. - pivot.valueFilter compares each item's total of a value field (the first by default) with a number or a range. - pivot.top10 keeps the top or bottom items by a value field, counted as items, a percent of the total or a sum. - pivot.clearFilter clears a field's filters, or every field's; a report filter stays in its area, showing all items. Value and Top 10 filters apply within each parent item, and subtotals and grand totals count only the items shown. As in Excel without "Allow multiple filters per field", a field has one kind of filter at a time: a rule replaces the field's item selection and the reverse. A rule follows its field between rows and columns and is dropped when the field moves to the filters area; value rules follow a renamed value field and go with a removed one; regrouping a field clears its label filter. pivot.list and pivot.fields report each rule. The PivotTable Fields pane gains Top 10 Items, Bottom 10 Items and Clear Filter in a field's menu, and no longer lists a row or column field's filter in the Filters area. XLSX: written as the pivotTableDefinition <filters> (caption*, value*, count, percent and sum filter types with their AutoFilter conditions) and read back; date filters are skipped with a warning.
|
I tested this PR at Warnings: "calculated items and label/value filters are not supported" no longer appears on any of the 9 files. Refresh compared with Excel's saved cells. I refreshed every PivotTable and compared its cells with the ones Excel saved:
On the files it affects, this PR makes a large difference: Idling Graph goes from 1,617 to 42, Driver Safety goes from 73/75 to 21/21 (0/0 with #722), and Active Faults Summary goes from 1,465 to 792 (0 with #722). With both PRs, 10 of the 26 PivotTables match Excel exactly. Of the 774 cells that still differ, 773 are items that tie on the sort value and come out in a different order (same rows, different order). The last one is a one-minute rounding difference in a summed duration. One behaviour difference: Top N with a tie at the cut-off. Excel keeps every item tied with the Nth value. GridCraft cuts at exactly N. In one report, a Top 15 filter on a row field (sorted by Speeding Events) has items 14, 15 and 16 all at 5. Excel shows 16 items, but this PR shows 15, so the PivotTable is one row shorter than Excel's. Merging. This PR conflicts with current
On that merge, the xlsx, engine and model tests pass, and the XLSX round trip shows 0 differences on all 11 files. |
Depends on #474. This branch is based on #474's two commits. Only the last commit belongs to this pull request.
Summary
This pull request adds Excel's label filters, value filters and Top 10 filters to the row and column fields of a PivotTable. Until now a PivotTable could only filter by selecting items (
pivot.filter). The filters are stored in the model, evaluated when the report is computed, and round-tripped through XLSX as the<filters>element of the PivotTable definition.Four commands are added:
pivot.labelFiltercompares each item's caption with a value or a range: equals, begins with, ends with, contains, their negations, greater than, less than, between and not between. The text comparisons accept*and?wildcards. Numbers compare as numbers, and case does not matter.pivot.valueFiltercompares each item's total of a value field with a number or a range. The value field defaults to the first.pivot.top10keeps the top or bottom items by a value field, counted as a number of items, a percent of the total or a sum.pivot.clearFilterclears the filters of one field, or of every field when no field is given.Sum of Sales by Region and Product, with a Top 10 filter that keeps the top product in each region. Subtotals and the grand total count only the items shown:
A label filter on Region (contains "st") combined with a value filter on the Product column field (total of at least 200):
Changes
Model
PivotCompare(the fourteen comparisons),PivotTopBy(items, percent, sum) andPivotRule.PivotRuleis a label rule, a value rule or a Top 10 rule. The value and Top 10 rules name their value field by caption.PivotFiltergainsrule: Option<PivotRule>.Engine
Commands
value2, a text comparison in a value filter, a value field that is not in the Values area, and Top 10 counts outside the valid range (a whole number of at least 1, or a percent greater than 0 and at most 100).pivot.filterwithselected: nullkeeps the field's rule.pivot.listandpivot.fieldsreport each rule in the parameters of the command that sets it.XLSX
<filters>afterpivotTableStyleInfo, as the schema orders them.caption*types andstringValue1andstringValue2. Value filters are written with thevalue*types andiMeasureFld. Top 10 filters are written with thecount,percentandsumtypes and atop10element. Each filter carries the AutoFilter conditions that express it.UI
Documentation
ROADMAP.mdprogress log anddocs/target-app-parity.md(PivotTables row, inventory and change log).Testing
label_filterschecks each kind of comparison, wildcards, bounds in either order, number captions, the interaction with item selection, reporting and clearing.value_and_top10_filterscovers value filters, Top 10 by items, percent and sum, another value field, renamed and removed value fields, Top 1 within each parent with its subtotal, a column field, moving a field between areas, and Clear Filter with a report filter in place.filters_round_trip_and_refusalschecks an XLSX round trip of a label filter and a bottom Top 10, the report after a refresh, and twelve refused parameter sets that leave the filters unchanged.hostile_params_never_paniccovers the new commands with two more hostile parameter sets.label_value_and_top10_filters_round_tripchecks the written XML and that the model compares equal after reading it back.unsupported_and_hostile_pivot_filterschecks that a date filter, a filter on a field that is not on an axis, and value filters with a missing value field or no number are skipped, and that a Top 10 without itstop10element takes Excel's defaults.-D warnings) pass.cargo test --workspace --no-fail-fastpasses except for three tests that already fail onmain: the French i18n coverage test and two semicolon CSV tests, which open pull requests already address.cargo xtask assets,layers,wasm,parityandkeytipspass, with no regenerated changes.Follow-ups
These are not part of this pull request.
multipleFieldFiltersin XLSX.discretePrround trip.Generative AI use: The code and descriptions in this pull request were written with the assistance of Claude Opus 5.5 (Claude Code). I directed the work, chose its scope, and reviewed and tested the changes.