<
OLAP for WPF and Silverlight | ComponentOne
OLAP for WPF and Silverlight Task-Based Help / Calculating Weighted Averages and Sums
In This Topic
    Calculating Weighted Averages and Sums
    In This Topic

    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:

    1. Right-click the field in the Values area of the C1OlapPanel and select Field Settings.
    2. Click the Subtotals tab and select the type of subtotal you want to calculate.
    3. In the Weigh by drop-down list, select the field from your data table that will be used as a weight.
    4. Click OK to close the Field Settings dialog box.

    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"];