Skip to main content

Calculate a Summary

  • 3 minutes to read

This document shows how to use summary functions to calculate a group summary. For more information on summary functions, review the following help topic: Summaries Overview.

The following images show a sample report with a summary:

Simple Summary Report in Designer

Simple Summary Report in Viewer

Follow the steps below to create a sample report with a 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:

    Add Data Source

  3. Create a data source and bind it to the SalesByCategory view from the nwind.db SQLite database. The database ships with the DevExpress installation package (the default path is C:\Users\Public\Public Documents\DevExpress Demos 21.2\Components\Data\nwind.db).

    Review the following help topic for more information on how to create a data source: Data Source Wizard.

    Install the System.Data.SQLite.Core NuGet package to use the SQLite database.

Group Data by Category

  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:

    Group and Sort panel

    To create grouping criteria, click Add a Group and select the CategoryName field from the invoked drop-down menu:

    Summary - Add a Group

  2. Select the Show Footer checkbox in the Group and Sort panel to add the Group Footer band:

    Add Group Footer Band

Add Report Controls to Display Data

  1. Click Field List in the Visual Studio XtraReports menu to invoke the Field List panel. Drop fields from the Field List panel to the report bands as follows:

    • CategoryName field to the Group Header band.
    • ProductName and ProductSales fields to the Detail band.
  2. Drop the XRLabel control onto the Group Footer band:

    Add Label to the Group Footer

Add a Summary

  1. Click the label’s smart tag. Then click the ellipsis next to the Summary editor to invoke the Summary Editor dialog.

    Summary Ellipsis

  2. The Summary Editor dialog allows you to specify the following options:

    • Summary running — specifies summary calculation range (the entire report, current report group, or current document page).
    • Summary function — specifies a summary function. When you hover over the information symbol, it shows a tooltip with information about the selected function.
    • Argument expression — specifies a data field or a complex expression.

    Review the following topic for a complete list of supported summary functions: Functions in Expressions.

    Summary Editor

    Select Sum as the summary function, Group as the calculation range, and ProductSales as the data field. Click OK to apply the settings.

  3. The Summary Editor assigns an expression to the XRLabel’s Expression editor:

    Summary Expression Smart Tag

  4. You can click the ellipsis next to the Expression editor to invoke the Expression Editor dialog:

    Summary Expression Editor Dialog

    The dialog allows you to edit the summary expression and change the summary function. For the current example, no changes are required. Click OK to close the dialog window.

  5. Switch to the Preview tab to see the resulting report.