Are Custom Aggregations Possible?

I have Year, Quarter, and Month columns that I would like to use to aggregate per day values. So instead of doing a normal sum, I need to sum the underlying values and divide by the number of days in the year, quarter, or month. Is this possible?


1 Reply 1 reply marked as answer

MM Manikandan Murugesan Syncfusion Team July 21, 2021 12:46 PM UTC

Hi Randy, 

Yes, you can modify the aggregated values in the pivot table by using "CellTemplate" option. For example, you can change the aggerated values by performing custom aggregation with the given cell information for each aggregated value obtained from the cell template. Please refer the following code example and sample below. 

Code Example: 
<SfPivotView TValue="PivotVirtualData" Width="100%" Height="100%" 
                     AllowDrillThrough="true"> 
            <PivotViewTemplates> 
                <CellTemplate> 
                    @{ 
                        var data = (context as AxisSet); 
                        if (data != null) 
                        { 
                            if (data.Axis == "value" && data.Index.Count > 0 && data.ActualText.ToString() == "Sold") 
                            { 
                                double value = 0; 
                                foreach (var index in data.Index) 
                                { 
                                    value = value + this.data[index].Sold; 
                                } 
                                value = value / data.Index.Count; 
                                @value 
                            } 
                            else 
                            { 
                                @data.FormattedText 
                            } 
                        } 
                    } 
                </CellTemplate> 
            </PivotViewTemplates> 
        </SfPivotView> 

 
Kindly refer the following UG document to know more about the cell template feature. 

 
Please let us know if you need further assistance with this. 

Regards, 
Manikandan 


Marked as answer
Loader.
Up arrow icon