Comments (1)
To resolve the issue where the Pivot Table (legacy) in Superset displays the Max value instead of the Sum, despite selecting 'Sum' as the Aggregation Function in the Pivot Options, you should ensure that the correct aggregator is being used. Here are the steps and checks you can perform:
-
Verify the Aggregation Function Configuration:
Ensure that theaggregateFunction
property in your Pivot Table configuration is set to 'Sum'. This can be done by setting theaggregateFunction
to 'Sum' in the control panel configuration.Example configuration:
const pivotTableConfig = { controlPanelSections: [ { label: t('Options'), expanded: true, controlSetRows: [ [ { name: 'aggregateFunction', config: { type: 'SelectControl', label: t('Aggregation function'), clearable: false, choices: [ ['Count', t('Count')], ['Sum', t('Sum')], // other choices... ], default: 'Sum', description: t('Aggregate function to apply when pivoting and computing the total rows and columns'), renderTrigger: true, }, }, ], // other controls... ], }, ], };
-
Check for Overrides or Custom Formatters:
Verify that there are no overrides or custom formatters affecting the aggregation. Ensure that the data being passed to the aggregator is correctly formatted. -
Verify the
aggregatorsFactory
Function:
TheaggregatorsFactory
function in thePivotTableChart
component defines the available aggregation functions, including 'Sum'. Ensure that the 'Sum' aggregator is correctly defined and used.const aggregatorsFactory = (formatter: NumberFormatter) => ({ Count: aggregatorTemplates.count(formatter), 'Count Unique Values': aggregatorTemplates.countUnique(formatter), 'List Unique Values': aggregatorTemplates.listUnique(', ', formatter), Sum: aggregatorTemplates.sum(formatter), Average: aggregatorTemplates.average(formatter), Median: aggregatorTemplates.median(formatter), 'Sample Variance': aggregatorTemplates.var(1, formatter), 'Sample Standard Deviation': aggregatorTemplates.stdev(1, formatter), Minimum: aggregatorTemplates.min(formatter), Maximum: aggregatorTemplates.max(formatter), First: aggregatorTemplates.first(formatter), Last: aggregatorTemplates.last(formatter), 'Sum as Fraction of Total': aggregatorTemplates.fractionOf( aggregatorTemplates.sum(), 'total', formatter, ), 'Sum as Fraction of Rows': aggregatorTemplates.fractionOf( aggregatorTemplates.sum(), 'row', formatter, ), 'Sum as Fraction of Columns': aggregatorTemplates.fractionOf( aggregatorTemplates.sum(), 'col', formatter, ), 'Count as Fraction of Total': aggregatorTemplates.fractionOf( aggregatorTemplates.count(), 'total', formatter, ), 'Count as Fraction of Rows': aggregatorTemplates.fractionOf( aggregatorTemplates.count(), 'row', formatter, ), 'Count as Fraction of Columns': aggregatorTemplates.fractionOf( aggregatorTemplates.count(), 'col', formatter, ), });
-
Check the
transformProps
Function:
Verify the transformation of chart properties in thetransformProps
function to ensure that theaggregateFunction
is correctly set to 'Sum'. Here is an example test case from thetransformProps
function:describe('PivotTableChart transformProps', () => { const setDataMask = jest.fn(); const formData = { groupbyRows: ['row1', 'row2'], groupbyColumns: ['col1', 'col2'], metrics: ['metric1', 'metric2'], tableRenderer: 'Table With Subtotal', colOrder: 'key_a_to_z', rowOrder: 'key_a_to_z', aggregateFunction: 'Sum', transposePivot: true, combineMetric: true, rowSubtotalPosition: true, colSubtotalPosition: true, colTotals: true, rowTotals: true, valueFormat: 'SMART_NUMBER', metricsLayout: MetricsLayoutEnum.COLUMNS, viz_type: '', datasource: '', conditionalFormatting: [], dateFormat: '', legacy_order_by: 'count', order_desc: true, currencyFormat: { symbol: 'USD', symbolPosition: 'prefix' }, }; const chartProps = new ChartProps<QueryFormData>({ formData, width: 800, height: 600, queriesData: [ { data: [{ name: 'Hulk', sum__num: 1, __timestamp: 599616000000 }], colnames: ['name', 'sum__num', '__timestamp'], coltypes: [1, 0, 2], }, ], hooks: { setDataMask }, filterState: { selectedFilters: {} }, datasource: { verboseMap: {}, columnFormats: {} }, theme: supersetTheme, }); it('should transform chart props for viz', () => { expect(transformProps(chartProps)).toEqual({ width: 800, height: 600, groupbyRows: ['row1', 'row2'], groupbyColumns: ['col1', 'col2'], metrics: ['metric1', 'metric2'], tableRenderer: 'Table With Subtotal', colOrder: 'key_a_to_z', rowOrder: 'key_a_to_z', aggregateFunction: 'Sum', transposePivot: true, combineMetric: true, rowSubtotalPosition: true, colSubtotalPosition: true, colTotals: true, rowTotals: true, valueFormat: 'SMART_NUMBER', data: [{ name: 'Hulk', sum__num: 1, __timestamp: 599616000000 }], setDataMask, selectedFilters: {}, verboseMap: {}, metricsLayout: MetricsLayoutEnum.COLUMNS, metricColorFormatters: [], dateFormatters: {}, emitCrossFilters: false, columnFormats: {}, currencyFormats: {}, currencyFormat: { symbol: 'USD', symbolPosition: 'prefix' }, }); }); });
By following these steps and ensuring that the aggregateFunction
is correctly set to 'Sum', you should be able to resolve the issue with the Pivot Table (legacy) displaying the Max value instead of the Sum. If the issue persists, please provide additional details or screenshots of your configuration and data to further diagnose the problem.
Details
Sources
- superset-frontend/plugins/plugin-chart-pivot-table/src/react-pivottable/utilities.js
- superset-frontend/plugins/plugin-chart-pivot-table/src/plugin/controlPanel.tsx
- superset-frontend/plugins/plugin-chart-pivot-table/src/PivotTableChart.tsx
- superset-frontend/plugins/plugin-chart-pivot-table/test/plugin/transformProps.test.ts
- superset-frontend/plugins/plugin-chart-pivot-table/src/plugin/transformProps.ts
About Dosu
This response is meant to be useful and save you time. It is not meant to be a precise solution, but rather a starting point for your own research.
Help me be more useful! Please leave a 👍 if this is helpful and 👎 if it is irrelevant.
To continue the conversation, mention @dosu.
from superset.
Related Issues (20)
- 🐛 Problems creating rows and columns in the superset. HOT 2
- Chart cache warmup fails with 405 Method Not Allowed HOT 1
- Superset can't access non-development environments HOT 5
- [Bug] Unable to edit mail list of existing alert & reports HOT 5
- Improper Input Validation while creating dashboard and charts HOT 1
- Can not specify recipient for slack or email for Superset Reports HOT 8
- Problem Exporting Charts as Diagram HOT 4
- Cannot fetch schema list and table list in sqllab after setting values to table_cache_timeout and schema_cache_timeout HOT 1
- Customize loading spinner position and appereance HOT 1
- New permalinks retain previous permalink activeTab state HOT 1
- No table names shown in Dataset creation window / SQL Lab for Apache Kyuubi HOT 1
- Add button grayed out even tough all fields are filled HOT 5
- Unable to execute any Superset command in terminal HOT 1
- Datasource access HOT 6
- Typo in IBM DB2 image reference in README.md HOT 2
- Gauge chart interval bounds and colors not working properly when added to a dashboard HOT 1
- Dataset access HOT 3
- Method 405 not allowed for guest_token fetching HOT 6
- There was an error loading the schemas HOT 4
- UUID columns show up as NULL HOT 1
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
D3
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
-
Recommend Topics
-
javascript
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
-
web
Some thing interesting about web. New door for the world.
-
server
A server is a program made to process requests and deliver data to clients.
-
Machine learning
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from superset.