[Expand]General Information
[Expand]WinForms Controls
[Expand]ASP.NET Controls and MVC Extensions
[Expand]ASP.NET Bootstrap Controls
[Expand]ASP.NET Core Bootstrap Controls
[Expand]WPF Controls
[Expand]Xamarin Controls
[Expand]Windows 10 App Controls
[Expand]Office File API
 [Expand]Product Information
 [Expand]Get Started with DevExpress Reporting
 [Expand]Create Popular Reports
 [Collapse]Detailed Guide to DevExpress Reporting
   Introduction to Banded Reports
  [Expand]Provide Data to Reports
  [Expand]Use Report Controls
  [Collapse]Shape Report Data
   [Expand]Filter Data
   [Collapse]Group and Sort
     Group and Sort a Report's Data
     Group Data by a Custom Field
     Group Data by Days of the Week
     Sort Data by a Custom Field
     Sort Groups by a Summary Function's Result
     Sort Data (Runtime Sample)
     Group Data (Runtime Sample)
     Group Data by Days of the Week (Runtime Sample)
   [Expand]Shape Data (Expression Bindings)
   [Expand]Shaping Data (Legacy Data Bindings)
   [Expand]Use Calculated Fields
   [Expand]Use Report Parameters
   Arrange Dynamic Report Contents
  [Expand]Customize Appearance
  [Expand]Add Navigation
  [Expand]Provide Interactivity
  [Expand]Add Extra Information
  [Expand]Merge Reports
  [Expand]Use Expressions
  [Expand]Store and Distribute Reports
  [Expand]Reporting API
 [Expand]Visual Studio Report Designer
 [Expand]Create End-User Reporting Applications
 [Expand]API Reference
[Expand]Report and Dashboard Server
[Expand]eXpressApp Framework
[Expand]eXpress Persistent Objects
[Expand]CodeRush Classic
[Expand]Cross-Platform Core Libraries
[Expand]Tools and Utilities
 End-User Documentation
View this topic on docs.devexpress.com (Learn more)

Group Data by a Custom Field

This tutorial illustrates how to group a report against a custom criteria at design time within Visual Studio. In the report created in this example, products are grouped by a calculated field that returns the first letter of the product name.

Do the following to group a report by a custom field:

  1. To create a table report in this tutorial, start with a report that is bound to the "Products" table of the sample Northwind database (the nwind.mdb file included in the XtraReports installation). To learn more about binding a report to a data source, see Provide Data to Reports.
  2. To create a calculated field, switch to the Field List, right-click any item inside the nwindDataSet1 and select Add Calculated Field in the menu that is invoked.

    As a result, the CalculatedField.DataMember property is automatically set to the "Products" table of the project's data set, which means that the calculated field can access data fields from this table.

  3. Next, select the created field, set its CalculatedField.Name property to Initial (the field's CalculatedField.DisplayName will be automatically set to the same value) and set the CalculatedField.FieldType property to String.

    Then click the ellipsis button for the calculated field's CalculatedField.Expression property, to invoke the Expression Editor.

  4. Define the following expression in the editor that is invoked: Substring([ProductName], 0 ,1 ). This will extract the initial letter from the ProductName data field.

    To close the editor and save the changes, click OK.

  5. To quickly create a Group Header band associated with the calculated field, use the Group and Sort panel.

    If the panel is not displayed, you can make it visible by checking the corresponding item in the XtraReports Menu.

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

    You can also use this panel to specify whether or not the corresponding Group Footer band should be visible. The Sort Order drop-down list allows you to define the sort order within the group (ascending or descending) or disable sorting in grouped data.

  6. Next, switch to the Field List and drop the required data fields onto the report's Detail band, and the Initial calculated field onto the Group Header area.

Expanded See Also

Is this topic helpful?​​​​​​​