question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

PivotTable doesn't corrently count total (SUM) in case of division metric

See original GitHub issue

Currelty 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 image 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

  1. 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
  1. Create Chart PivotTable v2 (visualization type = Pivot Table v2) based on dataset above.
  2. Populate rows as “gr” (Simple ABC gr) and “shem” (Simple ABC shem)
  3. 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) )
  4. In the Options area check “Show columns total” and select Aggregation functiona as “SUM”
  5. 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:open
  • Created a year ago
  • Comments:5 (4 by maintainers)

github_iconTop GitHub Comments

1reaction
mayurnewasecommented, Sep 14, 2022

use pivottable 2, this one is deprecated and has few bugs which are less likely to be fixed in the future.

0reactions
kgabryjecommented, Oct 21, 2022

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.

Read more comments on GitHub >

github_iconTop 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 >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found