superset icon indicating copy to clipboard operation
superset copied to clipboard

Feature Request : currently we can't summarize pivot table/ table as % value of row total/ column total/ grand total

Open dataneta opened this issue 8 years ago • 14 comments

Make sure these boxes are checked before submitting your issue - thank you!

  • [Y ] I have checked the superset logs for python stacktraces and included it here as text if any
  • [ Y] I have reproduced the issue with at least the latest released version of superset
  • [ Y] I have checked the issue tracker for the same issue and I haven't found one similar

Can we add a feature in visualization type "treemap", "pivot table","table" and "partition" which enable us to summarize data by % total of row total or column total or grand total

Superset version

Expected results

Actual results

Steps to reproduce

dataneta avatar Dec 13 '17 14:12 dataneta

How does this compare to the existing Percent Metrics feature in the table vis?

Mogball avatar Dec 19 '17 22:12 Mogball

Is "percent metric" option is available in "pivot table" also?

dataneta avatar Dec 20 '17 06:12 dataneta

Is "percent metric" option is available in "pivot table" also?

dataneta avatar Dec 20 '17 06:12 dataneta

Not currently

Mogball avatar Dec 20 '17 06:12 Mogball

This would be a useful feature to greatly extend the expressiveness of the pivot table chart, i.e., to represent "wide" vs "long" data.

To illustrate, suppose have data for school students with a letter grade for each subject. Further suppose that we would like to calculate the count by subject and grade. In this case, we can use either visualization type:

Table View

subject grade count
English A 50
English B 85
English C 39
English D 12
English F 0
Math A 44
... ... ...

Pivot Table

subject A B C D F all
English 50 85 39 12 0 186
Math 44 ... ... ... ... ...
... ... ... ... ... ... ...

If we now would like to see the percentage of students by letter grade within each subject, we are out of luck. Table View exposes "Percentage Metrics", but the percentages use the number of students across all subjects and letter grades as the denominator.

If, on the other hand, "Percentage Metrics" were implemented for Pivot Table and this added a percentage for each column calculated over the row total, we would be able to express the ask.

In any case, this would be a useful feature (although I'm sure there are design/implementation details to nail down), and hopefully the example above illustrates how such a feature would extend Superset's expressiveness in tabular "visualizations" even further.

circld avatar Jul 20 '18 18:07 circld

Is anyone working on this,is there a way to implement "Percentage Metrics" .i am new to superset so i need help.

hannanshaikh avatar Feb 12 '19 08:02 hannanshaikh

This issue has been automatically marked as stale because it has not had recent activity. It will be closed if no further activity occurs. Thank you for your contributions. For admin, please label this issue .pinned to prevent stale bot from closing the issue.

stale[bot] avatar Apr 13 '19 09:04 stale[bot]

Is anyone working on this?

94ksunny avatar Dec 14 '20 05:12 94ksunny

Anyone found way to do this?

sahildoshi013 avatar Feb 23 '22 07:02 sahildoshi013

@sahildoshi013 have you tried out "Pivot table v2"? It has an option to calculate percentages over row/column/total.

villebro avatar Feb 23 '22 08:02 villebro

@villebro Thanks, I am able to calculate percentages. but is there any way I can plot sum and percentage both at same time. just like normal table?

sahildoshi013 avatar Mar 01 '22 07:03 sahildoshi013

@sahildoshi013 unfortunately it's not yet possible to apply this logic per metric. However, in the meantime, you can create a secondary metric where you apply a window function where you divide your aggregate expression with the total for that row (feel free to customize the window function to your use case):

  1. First metric: COUNT(*)
  2. Second metric: 1.0 * COUNT(*) / SUM(COUNT(*)) OVER ()
image

villebro avatar Mar 01 '22 07:03 villebro

perfect! For the percentage column - for example profit - I used the expression below for percentages:

100 * sum(profit) / sum(sum(profit)) OVER ()

robjuffermans avatar Mar 09 '22 16:03 robjuffermans

As the values in the cells grow larger and larger, having a percentage metric with the count would be very helpful for analysis.

moksh-enf avatar Jul 29 '22 20:07 moksh-enf