There may be cases where it is necessary to find the weighted average or sum of your data. In a weighted average or sum, some data points contribute more to the subtotal than others.
Suppose you have a bound list of products and you want to find the average price for the group of products, taking into account the quantity of each product purchased. You can weight the price average by the number of units purchased. This can be done at run time by the user or in code.
To add weight to a calculation at run time:
To add weight to a calculation in code:
Use the C1OlapField.WeightField property to specify the field to be used as the weight. In this example, the Quantity field is the weight.
Visual Basic |
Copy Code
|
---|---|
Dim olap = Me.C1OlapPage1.OlapEngine Dim field = olap.Fields("Quantity") field.WeightField = olap.Fields(“Quantity”) |
C# |
Copy Code
|
---|---|
var olap = this.c1OlapPage1.OlapEngine; var field = olap.Fields["Quantity"]; field.WeightField = olap.Fields["Quantity"]; |