Ignore cell value based on condition when aggregate

Hello,

I have a numeric column but under specific conditions (for example when value is 9999) , I would like to ignore it from any aggregate functions.
So for example if I have 3 rows in my datasource of the column "Rate" with values 2,4,9999 , I would like when I setup an average function, the result to be 3.

Thank you in advance
Best Regards
Vangelis



3 Replies

SK Sridhar Karunakaran Syncfusion Team November 11, 2024 02:30 PM UTC

Hi Vangelis,

We understand that you need to customize specific value in the pivot table. If this is the case, you can utilize the aggregateCellInfo event to customize the value cells. In the code example provided below, we have customized the specific value (for instance, 9999) in the "Rate" column by assigning it the average of the previous row values that correspond to the current column. You can adapt this code according to your specific needs.

Please note that you can also access the raw data of a cell using args.cellSets within the event, which allows for additional customization.


Code example:

let values = [];

aggregateCellInfo: function (args) {

            // Check if the current cell value is 9999 and customize it

            if(args.column.valueSort.levelName == 'Rate' && args.value == 9999) {

                const average = values.reduce((acc, curr) => acc + curr, 0) / values.length;

                args.value = average

            } else if(args.column.valueSort.levelName == 'Rate') {

                // Otherwise store the other values that belong to the 'Rate' column.

                values.push(args.value)

            }

        },

 


Output screenshot:

Before customization:

After customization:

Meanwhile, We have modified the provided sample for your reference. You can find the sample at the following link.

Sample: https://stackblitz.com/edit/e9ut3h-nvvwa9?file=index.js


Furthermore, we have shared the documentation link to know more about aggregateCellInfo event.

Document: https://ej2.syncfusion.com/javascript/documentation/pivotview/aggregation#aggregatecellinfo


Please let us know if you have any concerns.


Regards,

Sridhar Karunakaran.



VK Vangelis Komninos November 11, 2024 02:47 PM UTC

Excellent !

Thank you for your valuable support


Regards

Vangelis



AP AngelinFaithSheeba PaulvannanRajadurai Syncfusion Team November 12, 2024 05:46 AM UTC

Hi Vangells,


Thank you for your update. We are delighted to hear that you are satisfied with the solution we provided. If you have any further questions or need assistance, please don't hesitate to contact us. We are always happy to assist you.


Regards,
Angelin Faith Sheeba.


Loader.
Up arrow icon