Skip to content

feat(pivot-table): reintroduce show-values-as-fraction display option - #42761

Open
rusackas wants to merge 4 commits into
masterfrom
feat/pivot-table-fraction-of
Open

feat(pivot-table): reintroduce show-values-as-fraction display option#42761
rusackas wants to merge 4 commits into
masterfrom
feat/pivot-table-fraction-of

Conversation

@rusackas

@rusackas rusackas commented Aug 4, 2026

Copy link
Copy Markdown
Member

SUMMARY

#41463 (SIP-216, merged via #41184) correctly moved Pivot Table totals/subtotals to DB-computed rollup queries, fixing non-additive metrics (ratios, COUNT_DISTINCT, AVG, etc.) that were previously wrong when re-aggregated client-side. As part of that change, the Pivot Table's old "Aggregation function" control was removed entirely, and its "Sum as Fraction of Total/Rows/Columns" options went with it.

That was collateral damage, not something the SIP identified as broken: those fraction variants only ever wrapped Sum/Count (both additive), so they were mathematically correct even before #41184, and users are now asking for the display mode back (originally raised against #41463).

This reintroduces it as a standalone "Show values as" control, rather than resurrecting the removed per-metric "Aggregation function" selector. The new architecture actually makes this cleaner than before: every cell already holds a DB-correct rollup value at every scope (its own cell, row total, column total, grand total), so showing a value as a fraction of one of those scopes is now a pure presentational transform at render time. It reuses react-pivottable's existing fractionOf template — the same one the old "Sum as Fraction of ..." options used — wrapping the current passthrough cellValue aggregator instead of sum()/count(), and reusing the same row/column/grand-total lookup (getAggregator) the removed feature relied on. No new query, no touching grouping_sets, no per-metric control to reintroduce.

Percentage display always uses a fixed percent format; a per-metric custom formatter (currency, decimals, etc.) doesn't apply to a ratio, so custom column formatters are skipped while a fraction mode is active (matching the old behavior, which also always used a fixed percent formatter regardless of the metric's own format).

BEFORE/AFTER SCREENSHOTS OR ANIMATED GIF

Pivot table of birth_names (rows = state, columns = gender, metric = sum__num, row/column totals on), cycling through the new control:

Actual values (default, unchanged behavior):

Actual values, with row and column totals

% of row total — every row (and the row-total column) sums to 100.0%:

Percent of row total

% of column total — every column (and the column-total row) sums to 100.0%:

Percent of column total

% of grand total — the grand-total corner reads 100.0%, every other cell is its share of it:

Percent of grand total

The control itself, alongside the rest of the Options panel:

Show values as control, dropdown open showing all four options

TESTING INSTRUCTIONS

  1. Create or open a Pivot Table chart with at least one row grouping, one column grouping, and one metric.
  2. In the Options panel, find the new Show values as control (below "Combine metrics") and select "% of row total", "% of column total", or "% of grand total".
  3. Confirm cell values re-render as percentages without a new query being issued (it's a renderTrigger control).
  4. Confirm each row's percentages sum to 100% in "% of row total" mode, each column's percentages sum to 100% in "% of column total" mode, and the grand total cell always reads 100%.
  5. Switch back to "Actual values" (the default) and confirm the original numeric display returns.
  6. npx jest --runInBand plugins/plugin-chart-pivot-table — all 96 tests pass, including 5 new tests covering all three fraction modes plus the default/unset case.
  7. npx tsc --noEmit -p plugins/plugin-chart-pivot-table/tsconfig.json and pre-commit run on the changed files both pass clean.

ADDITIONAL INFORMATION

Issue #41463 (SIP-216, merged via #41184) correctly moved pivot table
totals/subtotals to DB-computed rollup queries, fixing non-additive
metrics (ratios, COUNT_DISTINCT, AVG, etc.). As part of that, the
Pivot Table's old "Aggregation function" control was removed
entirely, taking its "Sum as Fraction of Total/Rows/Columns" options
down with it -- collateral damage, not something the SIP identified
as broken. Those variants only ever wrapped Sum/Count (both
additive), so they were already correct before #41184 and remain a
distinct, wanted feature independent of the non-additive-totals fix.

This reintroduces it as a standalone "Show values as" control rather
than resurrecting the old per-metric aggregator-override mechanism.
Now that every cell already holds a DB-correct rollup value at every
scope (row total, column total, grand total), showing a cell as a
fraction of one of those scopes is a pure presentational transform at
render time: reuse react-pivottable's existing fractionOf template,
wrapping the passthrough `cellValue` aggregator instead of `sum()`/
`count()`, and reuse the same row/column/grand-total lookup
(`getAggregator`) the removed feature relied on. No new query, no
touching grouping_sets, no per-metric control.

Percentage display always uses a fixed percent format; per-metric
custom formatters (currency, decimals, etc.) don't apply to a ratio,
so formattedAggregators is skipped while a fraction mode is active.
@bito-code-review

bito-code-review Bot commented Aug 4, 2026

Copy link
Copy Markdown
Contributor

Code Review Agent Run #f318ab

Actionable Suggestions - 0
Review Details
  • Files reviewed - 7 · Commit Range: cdb52e5..cdb52e5
    • superset-frontend/plugins/plugin-chart-pivot-table/src/PivotTableChart.tsx
    • superset-frontend/plugins/plugin-chart-pivot-table/src/plugin/controlPanel.tsx
    • superset-frontend/plugins/plugin-chart-pivot-table/src/plugin/transformProps.ts
    • superset-frontend/plugins/plugin-chart-pivot-table/src/react-pivottable/utilities.ts
    • superset-frontend/plugins/plugin-chart-pivot-table/src/types.ts
    • superset-frontend/plugins/plugin-chart-pivot-table/test/plugin/transformProps.test.ts
    • superset-frontend/plugins/plugin-chart-pivot-table/test/react-pivottable/tableRenders.test.tsx
  • Files skipped - 0
  • Tools
    • Whispers (Secret Scanner) - ✔︎ Successful
    • Detect-secrets (Secret Scanner) - ✔︎ Successful
    • Eslint (Linter) - ✔︎ Successful

Bito Usage Guide

Commands

Type the following command in the pull request comment and save the comment.

  • /review - Manually triggers a full AI review.

  • /pause - Pauses automatic reviews on this pull request.

  • /resume - Resumes automatic reviews.

  • /resolve - Marks all Bito-posted review comments as resolved.

  • /abort - Cancels all in-progress reviews.

Refer to the documentation for additional commands.

Configuration

This repository uses Superset You can customize the agent settings here or contact your Bito workspace admin at evan@preset.io.

Documentation & Help

AI Code Review powered by Bito Logo

@dosubot dosubot Bot added change:frontend Requires changing the frontend viz:charts:pivot Related to the Pivot Table charts labels Aug 4, 2026
@bito-code-review

Copy link
Copy Markdown
Contributor

The flagged issue is correct. The showValuesAs control exposes percentage options that require specific rollup levels (row, column, or grand totals) to calculate correctly. If these rollups are disabled in the pivot table configuration, the calculation logic will fail to find the required denominator, resulting in NaN% or Infinity% values.

To resolve this, you can update the controlPanel.tsx to conditionally disable these choices based on the state of the rollup toggles. You can use the visibility property in the control configuration to hide or disable the percentage options when the corresponding totals are not enabled.

Example implementation for controlPanel.tsx:

// Inside controlPanel.tsx, update the showValuesAs control configuration:
visibility: ({ controls }) => {
  const rowTotals = controls?.rowTotals?.value;
  const colTotals = controls?.colTotals?.value;
  // Logic to filter choices based on rowTotals/colTotals
  return { ... };
},

I have checked the available comments on this PR, and there are no other review comments to address. Would you like me to proceed with implementing this fix in the controlPanel.tsx file?

superset-frontend/plugins/plugin-chart-pivot-table/src/plugin/controlPanel.tsx

visibility: ({ controls }) => {
                const rowTotals = controls?.rowTotals?.value;
                const colTotals = controls?.colTotals?.value;
                // Logic to filter choices based on rowTotals/colTotals
                return { ... };
              },

@codecov

codecov Bot commented Aug 4, 2026

Copy link
Copy Markdown

Codecov Report

❌ Patch coverage is 76.00000% with 12 lines in your changes missing coverage. Please review.
✅ Project coverage is 65.78%. Comparing base (e103d92) to head (a2f6a55).
⚠️ Report is 30 commits behind head on master.

Files with missing lines Patch % Lines
...hart-pivot-table/src/react-pivottable/utilities.ts 66.66% 12 Missing ⚠️
Additional details and impacted files
@@            Coverage Diff             @@
##           master   #42761      +/-   ##
==========================================
+ Coverage   65.77%   65.78%   +0.01%     
==========================================
  Files        2840     2840              
  Lines      161983   162018      +35     
  Branches    37124    37148      +24     
==========================================
+ Hits       106545   106585      +40     
+ Misses      53373    53368       -5     
  Partials     2065     2065              
Flag Coverage Δ
javascript 72.02% <76.00%> (+0.01%) ⬆️

Flags with carried forward coverage won't be shown. Click here to find out more.

☔ View full report in Codecov by Harness.
📢 Have feedback on the report? Share it here.

🚀 New features to boost your workflow:
  • ❄️ Test Analytics: Detect flaky tests, report on failures, and find test suite problems.
  • 📦 JS Bundle Analysis: Save yourself from yourself by tracking and limiting bundle sizes in JS merges.

… totals toggle

`showValuesAs` percent modes (% of row/column/grand total) divide by a
rollup level that `buildGroupbyCombinations` only queried when the
matching Total/subtotal display toggle was on, so picking a percent
mode without enabling that toggle could crash on a missing denominator
aggregator. Force the required level(s) in and fall back to a blank
cell instead of throwing if one is ever still missing.

Co-Authored-By: Claude Opus 4.8 <noreply@anthropic.com>
@rusackas
rusackas requested a review from Vitor-Avila August 4, 2026 23:00
@rusackas rusackas added the 🎪 ⚡ showtime-trigger-start Create new ephemeral environment for this PR label Aug 4, 2026
@github-actions github-actions Bot added 🎪 490356d 🚦 building Environment 490356d status: building 🎪 490356d 📅 2026-08-04T23-02 Environment 490356d created at 2026-08-04T23-02 🎪 490356d 🤡 rusackas Environment 490356d requested by rusackas 🎪 ⌛ 48h Environment expires after 48 hours (default) and removed 🎪 ⚡ showtime-trigger-start Create new ephemeral environment for this PR labels Aug 4, 2026
@github-actions

github-actions Bot commented Aug 4, 2026

Copy link
Copy Markdown
Contributor

🎪 Showtime is building environment on GHA for 490356d

@rusackas rusackas removed the 🎪 ⌛ 48h Environment expires after 48 hours (default) label Aug 4, 2026
@github-actions github-actions Bot added 🎪 490356d 🚦 deploying Environment 490356d status: deploying and removed 🎪 490356d 🚦 building Environment 490356d status: building labels Aug 4, 2026
… pruning test

buildGroupbyCombinations iterates rows as the outer loop and columns as
the inner loop, so when both the rows-collapsed and columns-collapsed
levels are pruned in (the percent_total case), the rows-collapsed
level pairs with every column prefix before the leaf row prefix does
-- matching the row/col-only pruning tests directly above it. The new
percent_total test had those two entries swapped; order carries no
functional meaning downstream (transformProps/PivotData key off each
row's own tags, not array position), so this fixes the expectation
rather than the (correct) production code.
@github-actions github-actions Bot added 🎪 f4a5010 🚦 building Environment f4a5010 status: building 🎪 f4a5010 📅 2026-08-04T23-13 Environment f4a5010 created at 2026-08-04T23-13 🎪 f4a5010 🤡 rusackas Environment f4a5010 requested by rusackas 🎪 ⌛ 48h Environment expires after 48 hours (default) labels Aug 4, 2026
@github-actions

github-actions Bot commented Aug 4, 2026

Copy link
Copy Markdown
Contributor

🎪 Showtime deployed environment on GHA for 490356d

Environment: http://35.87.13.172:8080 (admin/admin)
Lifetime: 48h auto-cleanup
Updates: New commits create fresh environments automatically

@github-actions github-actions Bot added 🎪 f4a5010 📅 2026-08-04T23-13 Environment f4a5010 created at 2026-08-04T23-13 🎪 f4a5010 🚦 failed Environment f4a5010 status: failed 🎪 f4a5010 🤡 rusackas Environment f4a5010 requested by rusackas labels Aug 4, 2026
@bito-code-review

bito-code-review Bot commented Aug 5, 2026

Copy link
Copy Markdown
Contributor

Code Review Agent Run #3ef62b

Actionable Suggestions - 0
Review Details
  • Files reviewed - 4 · Commit Range: cdb52e5..f4a5010
    • superset-frontend/plugins/plugin-chart-pivot-table/src/plugin/utilities.ts
    • superset-frontend/plugins/plugin-chart-pivot-table/src/react-pivottable/utilities.ts
    • superset-frontend/plugins/plugin-chart-pivot-table/src/types.ts
    • superset-frontend/plugins/plugin-chart-pivot-table/test/plugin/utilities.test.ts
  • Files skipped - 0
  • Tools
    • Whispers (Secret Scanner) - ✔︎ Successful
    • Detect-secrets (Secret Scanner) - ✔︎ Successful
    • Eslint (Linter) - ✔︎ Successful

Bito Usage Guide

Commands

Type the following command in the pull request comment and save the comment.

  • /review - Manually triggers a full AI review.

  • /pause - Pauses automatic reviews on this pull request.

  • /resume - Resumes automatic reviews.

  • /resolve - Marks all Bito-posted review comments as resolved.

  • /abort - Cancels all in-progress reviews.

Refer to the documentation for additional commands.

Configuration

This repository uses Superset You can customize the agent settings here or contact your Bito workspace admin at evan@preset.io.

Documentation & Help

AI Code Review powered by Bito Logo

Comment thread superset-frontend/plugins/plugin-chart-pivot-table/src/plugin/controlPanel.tsx Outdated
…ric fraction cross-talk

Three follow-ups from review on the show-values-as-fraction feature:
- `showValuesAs` was `renderTrigger: true`, but it changes which rollup
  levels `buildGroupbyCombinations` requests for non-additive metrics, so
  switching it needs a real requery, not a client-side-only re-render.
- The `combineMetric` filter in `buildGroupbyCombinations` stripped the
  percent-mode denominator level back out whenever it landed on the
  opposite axis from the kept metrics-layout level, blanking percentages
  with Combine metrics enabled.
- With multiple metrics sharing an axis, `fractionOf`'s grand/row/column
  total lookup hit the same metric-blind "Metric-collapse totals" slot for
  every metric, so all but the last metric divided by the wrong total.
  `fractionOf` now keeps the pushing record's own metric key in the
  selector so the lookup resolves to that metric's own total.

Co-Authored-By: Claude Opus 4.8 <noreply@anthropic.com>
@netlify

netlify Bot commented Aug 5, 2026

Copy link
Copy Markdown

Deploy Preview for superset-docs-preview ready!

Name Link
🔨 Latest commit a2f6a55
🔍 Latest deploy log https://app.netlify.com/projects/superset-docs-preview/deploys/6a72d7504169bb0009310912
😎 Deploy Preview https://deploy-preview-42761--superset-docs-preview.netlify.app
📱 Preview on mobile
Toggle QR Code...

QR Code

Use your smartphone camera to open QR code link.
🤖 Make changes Run an agent on this branch

To edit notification comments on pull requests, go to your Netlify project configuration.

@github-actions github-actions Bot added 🎪 a2f6a55 🚦 building Environment a2f6a55 status: building 🎪 a2f6a55 📅 2026-08-05T06-30 Environment a2f6a55 created at 2026-08-05T06-30 🎪 a2f6a55 🤡 rusackas Environment a2f6a55 requested by rusackas labels Aug 5, 2026
@github-actions

github-actions Bot commented Aug 5, 2026

Copy link
Copy Markdown
Contributor

🎪 Showtime is building environment on GHA for a2f6a55

@github-actions github-actions Bot added 🎪 a2f6a55 🚦 deploying Environment a2f6a55 status: deploying 🎪 a2f6a55 🚦 running Environment a2f6a55 status: running 🎪 🎯 a2f6a55 Active environment pointer - a2f6a55 is receiving traffic 🎪 a2f6a55 🌐 54.191.252.119:8080 Environment a2f6a55 URL: http://54.191.252.119:8080 (click to visit) and removed 🎪 a2f6a55 🚦 building Environment a2f6a55 status: building 🎪 a2f6a55 🚦 deploying Environment a2f6a55 status: deploying 🎪 a2f6a55 🚦 running Environment a2f6a55 status: running 🎪 🎯 a2f6a55 Active environment pointer - a2f6a55 is receiving traffic 🎪 490356d 📅 2026-08-04T23-02 Environment 490356d created at 2026-08-04T23-02 🎪 490356d 🌐 35.87.13.172:8080 Environment 490356d URL: http://35.87.13.172:8080 (click to visit) 🎪 490356d 🤡 rusackas Environment 490356d requested by rusackas 🎪 490356d 🚦 running Environment 490356d status: running 🎪 f4a5010 🤡 rusackas Environment f4a5010 requested by rusackas 🎪 f4a5010 📅 2026-08-04T23-13 Environment f4a5010 created at 2026-08-04T23-13 🎪 f4a5010 🚦 failed Environment f4a5010 status: failed labels Aug 5, 2026
@github-actions

github-actions Bot commented Aug 5, 2026

Copy link
Copy Markdown
Contributor

🎪 Showtime deployed environment on GHA for a2f6a55

Environment: http://54.191.252.119:8080 (admin/admin)
Lifetime: 48h auto-cleanup
Updates: New commits create fresh environments automatically

@bito-code-review

bito-code-review Bot commented Aug 5, 2026

Copy link
Copy Markdown
Contributor

Code Review Agent Run #4f2494

Actionable Suggestions - 0
Additional Suggestions - 1
  • superset-frontend/plugins/plugin-chart-pivot-table/src/react-pivottable/utilities.ts - 1
    • Missing unit tests for metricAxis logic · Line 763-783
      The `metricAxis` logic in `push()` captures which axis holds the metric but has no test coverage. Adaptive rule [11730] requires unit tests for new features. At minimum, test that multiple metrics with fraction-of-row correctly route to per-metric totals instead of sharing a collapsed total.
Review Details
  • Files reviewed - 4 · Commit Range: f4a5010..a2f6a55
    • superset-frontend/plugins/plugin-chart-pivot-table/src/plugin/controlPanel.tsx
    • superset-frontend/plugins/plugin-chart-pivot-table/src/plugin/utilities.ts
    • superset-frontend/plugins/plugin-chart-pivot-table/src/react-pivottable/utilities.ts
    • superset-frontend/plugins/plugin-chart-pivot-table/test/react-pivottable/tableRenders.test.tsx
  • Files skipped - 0
  • Tools
    • Whispers (Secret Scanner) - ✔︎ Successful
    • Detect-secrets (Secret Scanner) - ✔︎ Successful
    • Eslint (Linter) - ✔︎ Successful

Bito Usage Guide

Commands

Type the following command in the pull request comment and save the comment.

  • /review - Manually triggers a full AI review.

  • /pause - Pauses automatic reviews on this pull request.

  • /resume - Resumes automatic reviews.

  • /resolve - Marks all Bito-posted review comments as resolved.

  • /abort - Cancels all in-progress reviews.

Refer to the documentation for additional commands.

Configuration

This repository uses Superset You can customize the agent settings here or contact your Bito workspace admin at evan@preset.io.

Documentation & Help

AI Code Review powered by Bito Logo

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

Labels

🎪 a2f6a55 🚦 running Environment a2f6a55 status: running 🎪 a2f6a55 🤡 rusackas Environment a2f6a55 requested by rusackas 🎪 a2f6a55 🌐 54.191.252.119:8080 Environment a2f6a55 URL: http://54.191.252.119:8080 (click to visit) 🎪 a2f6a55 📅 2026-08-05T06-30 Environment a2f6a55 created at 2026-08-05T06-30 change:frontend Requires changing the frontend plugins preset-io size/L viz:charts:pivot Related to the Pivot Table charts 🎪 ⌛ 48h Environment expires after 48 hours (default)

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants