Back to Devexpress

Calculate a Weighted Average

xtrareports-117095-feature-guide-to-devexpress-reports-shape-report-data-calculate-summaries-calculate-a-weighted-average.md

latest2.8 KB
Original Source

Calculate a Weighted Average

  • Feb 18, 2026
  • 3 minutes to read

This topic describes how to create a report that calculates a weighted average summary.

The sample report calculates the weighted average price by product for a company to which a product has been shipped. The report shows the product, the companies to which the product is shipped, and the weighted average price for that product:

Follow the steps in the sections below to create a sample report with a weighted average summary.

Bind a Report to Data

  1. Add a new blank report to the project. Review the following help topic for details: Create a Report in Visual Studio.

  2. Click Add Report Data Source in the report’s smart tag to invoke the Data Source Wizard , as illustrated in the following image:

  3. Create a data source bound to the sample Northwind database.

  4. In the Data Source Wizard, click the plus (+) button to create a new query:

  5. In the invoked Query Builder window, select tables and fields, and add relations as follows:

Group the Report Data

  1. Use the Group and Sort panel to create a Group Header band associated with the CategoryName field. If the panel is hidden, click Group and Sort in the XtraReports menu:

  2. To create a nested group, click Add a Group and select the ShipName field from the menu. Select the Show Footer checkbox in the Group and Sort panel to add the Group Footer band. The resulting Group and Sort panel is shown below:

Add Report Controls to Display Data

Drop fields from the Field List window to report bands to create data-bound XRLabel controls that display data:

Add a Summary

  1. Drop the XRLabel control from the Toolbox to the Group Footer band. Click the ellipsis next to the Summary editor in the label’s smart tag to invoke the Summary Editor :

  2. In the Summary Editor dialog you should set the following options:

  3. The Summary Editor settings are automatically converted to an expression that is assigned to the label’s Expression property:

  4. Click the ellipsis next to the Expression editor to invoke the Expression Editor dialog and adjust the formula as follows:

  5. Switch to the Preview tab to see the result.