Kuaffu commented on issue #32260: URL: https://github.com/apache/superset/issues/32260#issuecomment-2661746830
> Hey [@Kuaffu](https://github.com/Kuaffu)! I'm here to help you with any bugs, questions, or contributions you have for Superset. Let's work together to solve this issue! > > To address the issue of incorrect subtotal and sum calculation of completion percentage in a pivot table, you can use the "Sum over Sum" aggregator template. This aggregator calculates the ratio of the sum of two fields, which is what you need for calculating "sum(actual_amount) / sum(target_amount)". > > Here's how you can implement it: > > const { sumOverSum } = aggregatorTemplates; > > // Use the sumOverSum aggregator with the actual_amount and target_amount fields > const completionPercentageAggregator = sumOverSum(['actual_amount', 'target_amount']); > This approach ensures that the completion percentage is calculated as the sum of actual amounts divided by the sum of target amounts, rather than summing the individual completion percentages [[1]](https://github.com/apache/superset/blob/master/superset-frontend/plugins/plugin-chart-pivot-table/src/react-pivottable/utilities.js). > > _To continue talking to [Dosu](https://dosu.dev), mention [@dosu](https://github.com/dosu)._ > > Help Dosu learn! Give it feedback: [Great Response](https://app.dosu.dev/response-feedback/5eb2b889-bc49-4072-bc1b-028ca53f7487?feedback_type=great_response) | [Irrelevant Answer](https://app.dosu.dev/response-feedback/5eb2b889-bc49-4072-bc1b-028ca53f7487?feedback_type=irrelevant_answer) | [Incorrect Sources](https://app.dosu.dev/response-feedback/5eb2b889-bc49-4072-bc1b-028ca53f7487?feedback_type=incorrect_sources) | [Too Verbose](https://app.dosu.dev/response-feedback/5eb2b889-bc49-4072-bc1b-028ca53f7487?feedback_type=too_verbose) | [Hallucination](https://app.dosu.dev/response-feedback/5eb2b889-bc49-4072-bc1b-028ca53f7487?feedback_type=hallucination) | [Bug Report](https://app.dosu.dev/response-feedback/5eb2b889-bc49-4072-bc1b-028ca53f7487?feedback_type=bug_report) | [Other](https://app.dosu.dev/response-feedback/5eb2b889-bc49-4072-bc1b-028ca53f7487?feedback_type=other) This only solves the current issue. When actual_amount or target_amount is not dragged, it still cannot calculate sum(actual_amount) / sum(target_amount) -- This is an automated message from the Apache Git Service. To respond to the message, please log on to GitHub and use the URL above to go to the specific comment. To unsubscribe, e-mail: [email protected] For queries about this service, please contact Infrastructure at: [email protected] --------------------------------------------------------------------- To unsubscribe, e-mail: [email protected] For additional commands, e-mail: [email protected]
