Custom Aggregation
RadPivotGrid is designed to aggregate data and it provides an API for assigning special aggregation functions performing custom calculations. For the purpose of this example we will use a LocalDataSourceProvider object and we will bind the pivot control to the Orders table from the Northwind database as explained here.
Figure 1: Using the Built-in Sum function
Figure 2: Using the Custom Sqrt Of Sum function
Defining a Custom Aggregation Function
Our new function will be almost the same as the already available AggregateFunctions.Sum, with the important difference that it will calculate not the sum of the items, but the sum of their square roots.
Custom Function Logic
Defining a Custom Aggregate Value
We also need to create a custom aggregate value class which will be used by our newly defined function to perform the actual calculation.
Custom Aggregate Logic
Assigning the Custom Function
We can make use of our new function by assigning it to the AggregateFunction property of a PropertyAggregateDescription object before setting it to our pivot.
The Custom Dialogs article demonstrates how the custom function can be added to the Aggregate Options Dialog.
Using the Custom Aggregate Function
If you add calculated fields in code behind, you have to set the ItemsSource of LocalDataSourceProvider after you have added all calculated fields or to wrap the code between (including setting the ItemsSource ) BeginInit/EndInit methods (or inside using DeferRefresh() { ... } section ).
Figure 2: Calculated Field in RadPivotGrid