apache / superset

Apache Superset is a Data Visualization and Data Exploration Platform
https://superset.apache.org/
Apache License 2.0
61.58k stars 13.44k forks source link

Pivot table cannot validly group rows and keep ordering #20564

Open comdiv opened 2 years ago

comdiv commented 2 years ago

While we have only one row ordering field but can add multiple row dimensions it's assumed that when we set order by value decending it will be work same way as with order by a-z:

  1. first row as group is ordered by a-z
  2. then second row inside group ordering by a-z

But if you choose order by value - it's breaking all groupping - all group rows occures multiple times in pivot!

Hard to explain how to exactly reproduce it.

Just compre two variances of ordering a-z and by value

image

As you can see - it cause valid behavior - group ordering then subgroup ordering

But try to set another option

image

It breaks table! Group is splitting and Subtotals not counted as expected!!!!

comdiv commented 2 years ago

superset-frontend/plugins/plugin-chart-pivot-table/src/react-pivottable/utilities.js:694

  case 'value_a_to_z':
          this.rowKeys.sort((a, b) => naturalSort(v(a, []), v(b, [])));
          break;
        case 'value_z_to_a':
          this.rowKeys.sort((a, b) => -naturalSort(v(a, []), v(b, [])));
          break;

doesn't reqalculate subtotals so cannot sort them correctly

comdiv commented 2 years ago

Have fix it for own usage, but may be it could be incorporated in main repository https://github.com/apache/superset/pull/20588

all known issues with sort fixed

rusackas commented 7 months ago

Just to drop a note here, I'm trying to get an ephemeral environment up to test the PR. Hopefully we can get this merged, but more pivot table expertise would be nice for testing.

rusackas commented 3 months ago

Assuming this is still an issue in current Superset? I'm trying again to spin up a test environment, but hoping @kgabryje can help test/review as well.

JZ6 commented 1 month ago

yes it is still an issue