PivotGrid - calculateCustomSummary Incorrect Percentage Calculation for Grouped Rows

24 Views Asked by At

I'm using the PivotGrid from devExpress in Angular and facing an issue with the calculateCustomSummary.

As you can see below, I'm calculating a column's value based on two other column values. It involves a percentage calculation, simply dividing one product value by another.

The problem is that it only calculates correctly for individual values. When the row is grouping more than one product value and displaying the sum of the values, the calculation becomes inaccurate.

I also have the same grid implemented in Delphi, where it calculates correctly. I have attached two screenshots, one from the Angular app showing the problem, and the other from the Delphi version with no errors.

What should I do to ensure it calculates correctly?


       {
        caption: '% M.C.',
        summaryType: 'custom',
        area: 'data',
        format: {
          precision: 2,
        },
        allowCrossGroupCalculation: true,

        calculateCustomSummary: (options: any) => {
          if (options.summaryProcess === 'calculate') {
            if (options.value.VALORMARGEMCONTRIBUICAO < 0) {
              options.totalValue = 0;
            }
            options.totalValue =
              (options.value.VALORMARGEMCONTRIBUICAO /
                options.value.VALORTOTAL) *
              100;

            return options.totalValue;
          } else {
            return options.totalValue;
          }
        },
      },

Image of Delphi Version with all calcs corrects

Image of Angular Version with calc issues

I have also tried the selector method of pivotGridDataSource to calculate the values, but got a even worse result bdw

0

There are 0 best solutions below