PivotTable doesn't corrently count total (SUM) in case of division metric
See original GitHub issueCurrelty Superset (v.1.5.1 and also in v.2.0.0) for Chart PivotTable (v1 and v2) doesn’t corrently count total/subtotal (SUM aggregation) in case of division metric exists.
For example:
Let’s create PivotTable, add metrics and populate as following
Where is “proc” column is metric with function “SUM(fm) / SUM(gmv)” . As you can see Total (Sum) is 2.7 , but it should be 165M / 376M ~= 0.4388 . So Superset just SUM column “proc” values instead of direct division.
How to reproduce the bug
- Create dataset “default.test_pivot”, for instance using following SQL:
SELECT 34523.323 as gmv, 24523.323 as fm, '1' as shem, '1' as gr
UNION all
SELECT 325323543.323 as gmv, 125323543.323 as fm, '2' as shem, '1' as gr
UNION all
SELECT 5764545.323 as gmv, 4764545.323 as fm, '3' as shem, '2' as gr
UNION all
SELECT 45254525.323 as gmv, 35254525.323 as fm, '4' as shem, '2' as gr
- Create Chart PivotTable v2 (visualization type = Pivot Table v2) based on dataset above.
- Populate rows as “gr” (Simple ABC gr) and “shem” (Simple ABC shem)
- Create metrics:
- SUM(gmv) (Simple , Column = gmv, aggregate = SUM)
- SUM(fm) (Simple , Column = fm, aggregate = SUM)
- proc (Custom SQL with value SUM(fm) / SUM(gmv) )
- In the Options area check “Show columns total” and select Aggregation functiona as “SUM”
- Run (evaluate values for Chart)
Expected results
Total (Sum) should be 165M / 376M ~= 0.4388 . The same for Subtotal correspondingly
Actual results
Total (Sum) is 2.7 , just SUM column “proc” values instead of direct division.
Screenshots
See above.
Environment
- browser type and version: chrome 105.0.5195.102 (64bit version)
- superset version: 1.5.1
- python version: 3.8.12
- node.js version: any
- any feature flags active: any
Checklist
Checked:
- I have checked the superset logs for python stacktraces and included it here as text if there are any.
- I have reproduced the issue with at least the latest released version of superset.
- I have checked the issue tracker for the same issue and I haven’t found one similar.
Additional context
If some workaround exists it will be also good.
Issue Analytics
- State:
- Created a year ago
- Comments:5 (4 by maintainers)
Top Results From Across the Web
Spreadsheets: Why Pivot Tables Won't Sum - CFO Magazine
Reason No. If you have a dataset with 50,000 rows of numbers and one blank cell in the middle, the pivot table will...
Read more >Pivot Table Defaults to Count Instead of Sum & How to Fix It
Learn how to get the pivot table to default to a Sum calculation instead of Count when the source data field contains numbers....
Read more >Excel Pivot Table Summary Functions Sum Count Change
In an Excel pivot table, Values are shown as Sum or Count. Learn why this happens, and see how to change to other...
Read more >[Bug 0.37.2 Pivot Table] Pivot table not work correctly ... - GitHub
Pivot table not work correctly with Sum Total I have a Pivot Table with: Distributor Code / Sum of Quantity / Sum of...
Read more >Three "Work-Arounds" for Calculated Fields in Excel Pivot ...
A Calculated Field is a "virtual field" in an Excel Pivot Table.You create a new field as a result of a formula that...
Read more >
Top Related Medium Post
No results found
Top Related StackOverflow Question
No results found
Troubleshoot Live Code
Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free
Top Related Reddit Thread
No results found
Top Related Hackernoon Post
No results found
Top Related Tweet
No results found
Top Related Dev.to Post
No results found
Top Related Hashnode Post
No results found

use pivottable 2, this one is deprecated and has few bugs which are less likely to be fixed in the future.
Hey @derichev-ozon! Like @mayurnewase said, it’s working as intended - we’re showing a sum in total and subtotals regardless of SQL behind given column. I can totally see a value in what you’re expecting. I think we should treat it as a new feature request - overriding global aggregation function for specific column.