Skip to main content
A newer version of this page is available. .

Calculate a Weighted Average


Follow the steps below to calculate a weighted average for Unit Price (weight values are taken from the Units in Stock field):

  1. Open an existing reporting application or create a new one from scratch.
  2. Bind a report to the sample Northwind database’s Products table (the nwind.mdb file is included in the XtraReports installation).
  3. Use the Group and Sort Panel to group the report data by the CategoryName data field and construct a layout like the following:


  4. Add the Group Footer band to the report and drop a XRLabel control on this band to display the summary result. Click the label’s smart tag, then click the Summary field’s ellipsis button.


  5. In the invoked Summary Editor window:

    • Set the Summary Running property to Group.
    • Set the Summary Function property to Weighed average.
    • Set the Argument Expression property to [UnitPrice], and the Weight property to [UnitsInStock]


  6. You can also use the control’s Format String property to format the summary value. For instance, set this property to Weighted Average Price: {0:c2}.