Calculate a Running Summary

  • 4 minutes to read

This topic describes how to calculate a running summary across report groups. A running summary adds the current summary value to the previously calculated summaries.

The sample report shows current summaries by year for sales of the specified product:

Report with Running Summary

View Example: Reporting for WinForms - How to Create a Report with Running Totals

Follow the steps in the sections below to create a sample report with a running 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 bound to the ProductReports view in 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.

  4. Filter report data to display only the specified product:

    Specify Filter String

    To specify a filter expression, invoke the report’s smart tag and click the ellipsis next to the Filter String editor. Construct the following criterion in the FilterString Editor window:

    [ProductName] = 'Tofu'
    

    Optional: You can add a report parameter to allow users to specify the product at runtime. For more information, review the following help topic: Create a Report Parameter.

Add a Calculated Field to Calculate a Year Value

  1. Click Field List in the Visual Studio XtraReports menu to invoke the Field List panel. Right-click any field and select Add Calculated Field:

    Add Calculated Field

  2. Right-click the newly created field and select Edit Expression to invoke the Expression Editor dialog:

    Edit Calculated Field Expression

  3. Enter the following expression that calculates the year value for the ShippedDate data field:

    GetYear([ShippedDate])
    

    Calculated Field Expression Editor

  4. In the Properties window, rename the calculated field to calcYear. Alternatively, right-click the field in the Field List and select Edit Calculated Fields to invoke the Calculated Field Collection Editor where you can specify the field name.

Group Data by Year

  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 calcYear 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. Drop fields from the Field List window to report bands to create data-bound XRLabel controls that display data:

    Drop Fields to Display Data

  2. Use the Format String editor in the label’s smart tag to specify how to display data.

  3. Right-click the report’s design area and select Insert Band - Report Header to add the Report Header band.
  4. Drop the ProductName field from the Field List window to the Report Header band to create a label. Use the label’s Format String editor to enter a string to display:

    Format Report Header

Add a Running 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:

    Summary Label Smart Tag

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

    Summary running
    Specifies the summary calculation range (the entire report, current report group, or current document page). Select Report from the drop-down list.
    Summary function
    Specifies the summary function. When you hover over the information symbol, it shows a tooltip with information about the selected function. Select RunningSum from the drop-down list.
    Argument expression
    Specifies a data field. Select [Product Sales].

    Summary Editor

    Click OK to close the dialog window.

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

    Summary Label Expression

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

    The dialog allows you to edit the summary expression and change the summary function. Review the following topic for a list of supported summary functions: Functions in Expressions.

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

See Also