The FlexPivot control allows users to calculate weighted average or sum of the data. This can be done both at runtime as well as in code. For example, consider a scenario where the user wants to find the average price for a group of products, taking into account the quantity of each purchased product. You can weigh the price average by the number of units purchased.
You can use the Subtotal property to calculate subtotals programmatically and the WeightField property to specify the field to be used as weight. The following code uses Quantity field as the Weight. This implementation uses the sample created in Quick Start topic.
C# |
Copy Code
|
---|---|
//Setting weight field in code var Qfield = fpEngine.Fields["Quantity"]; Qfield.WeightField = fpEngine.Fields["Quantity"]; //Show weighted average price fpEngine.Fields["ExtendedPrice"].Subtotal = Subtotal.Average; |