Results 1 to 2 of 2

Thread: Pivot Grid; Multiple Values with `aggregator: groupSumPercentage` returns same result

    Thank you for reporting this bug. We will make it our priority to review this report.
  1. #1

    Default Pivot Grid; Multiple Values with `aggregator: groupSumPercentage` returns same result

    Hello;

    Whenever `PivotGrid.matrix.aggregate` gets two fields with `aggregator: groupSumPercentage` then calculation always rendering first field's result into second one as well.
    Below you'll find a `PivotGrid` Sencha Fiddle which has `pivotconfigurator` and by default arranged to has two values with aggregator: groupSumPercentage.

    Bug Demonstration: Please just relocate available `Qty` and `Value` values on `Values Panel` of Pivotconfigurator and you'll notice PivotGrid will always render first field's value to second one as well.
    Values Panel: https://www.evernote.com/l/ASLGYXEjb...5loB/image.png
    Sencha Fiddle: https://fiddle.sencha.com/#view/editor&fiddle/31bv

    Looking forward for a solution.
    Thank you very much.

  2. #2

    Default

    Quote Originally Posted by nuridesengin View Post
    Hello;

    Whenever `PivotGrid.matrix.aggregate` gets two fields with `aggregator: groupSumPercentage` then calculation always rendering first field's result into second one as well.
    Below you'll find a `PivotGrid` Sencha Fiddle which has `pivotconfigurator` and by default arranged to has two values with aggregator: groupSumPercentage.

    Bug Demonstration: Please just relocate available `Qty` and `Value` values on `Values Panel` of Pivotconfigurator and you'll notice PivotGrid will always render first field's value to second one as well.
    Values Panel: https://www.evernote.com/l/ASLGYXEjb...5loB/image.png
    Sencha Fiddle: https://fiddle.sencha.com/#view/editor&fiddle/31bv

    Looking forward for a solution.
    Thank you very much.
    Hello again; I've found my own work-around within defining my own aggregator method till bug-fix going to come.
    Hope will be useful for any other if has similar needs.

    + I'll update bug-fixed Fiddle sample as well. Thanks.

    Code:
    /**
         * Framework BUG fix for Ext.pivot.Aggregators-method-groupSumPercentage;
         *
         * # Bug Info:
         * Original METHOD creates incorrect Percent value for field/measure when process more then one field/measure.
         * Bug sample can be found on Fiddle {@link https://fiddle.sencha.com/#view/editor&fiddle/31bv}
         * Framework source code {@link https://docs.sencha.com/extjs/6.7.0/classic/src/Aggregators.js.html#Ext.pivot.Aggregators-method-groupSumPercentage}
         *
         * # Fix Info: Method context works with {@link OWeb.PivotViewController.config.currentGrandTotal}
         * `Ext.pivot.Aggregators.sum()` first it always returns `GRANDTOTAL` of current measure and then other values.
         * Thus sealing the first `output` within `ViewController.config` and using this value for percentage calculation with GrandTotal. 
         *
         *  1. Check and create grand total value. 
         *  2. Create current measure total value.
         *  3. Calculate measure total within grand total.
         *
         * @param {Array} records Records to process.
         * @param {String} measure Field to aggregate by.
         * @param {Ext.pivot.matrix.Base} matrix The matrix object reference.
         *
         * @return {Number}
         */
        owebGroupSumPercentage: function(records, measure, matrix) {
            let me = this, value,
                sumFn = Ext.pivot.Aggregators.sum,
                measureTotal = matrix.calculateAsExcel ? null : 0;
    
    
            // Get Available Grand Total keys.
            let grandTotalKeys = !Ext.isEmpty(me.getCurrentGrandTotal()) ? Object.keys(me.getCurrentGrandTotal()) : null;
    
    
            // Check if current measure has Grand Total key.
            let hasKey = !Ext.isEmpty(grandTotalKeys) ? grandTotalKeys.includes(measure): false;
    
    
            // Set Grand Total
            if (!hasKey) {
                Object.assign(me.getCurrentGrandTotal(), {[measure]: sumFn(records, measure, matrix)});
            }
    
    
            // Get current measure total.
            records.forEach(record => {
                value = record.get(measure);
    
    
                if (value !== null) {
                    if (measureTotal === null) {
                        measureTotal = 0;
                    }
    
    
                    if (typeof value === 'number') {
                        measureTotal += value;
                    }
                }
            });
    
    
            // Calculate percent value and return.
            return measureTotal * 100 / me.getCurrentGrandTotal()[measure];
        }

Tags for this Thread

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •