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

Group Data by Days of the Week

  • 3 minutes to read

This tutorial illustrates how to group a report by days of the week. This approach can also be used to group data by month, or any other time span value.

GroupByTimeSpan_6

Do the following to group a report’s data by days of the week:

  1. To create a table report in this tutorial, start with a report that is bound to the “Orders” 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. Create a calculated field. To do this, switch to the Field List, right-click any item inside the nwindDataSet1, and select Add Calculated Field in the invoked menu.

    GroupByTimeSpan_1

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

  3. The calculated field that was created in the previous step will return a zero-based index of the day of the week, extracted from the [OrderDate] data field. To do this, select the calculated field, and in the Properties window, click the ellipsis button for the CalculatedField.Expression property, to invoke the Expression Editor.

    GroupByTimeSpan_2

    In this dialog, select the required date-time function , and define the data field’s name in [square brackets]. For this example, you will use the GetDayOfWeek([OrderDate]) function.

    GroupByTimeSpan_3

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

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

    design-panels-xtrareports-menu

    Click Add a Group, and in the invoked drop-down menu, select the calculated field.

    GroupByTimeSpan_4

    You can also use this panel to specify whether or not the corresponding GroupFooter 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.

  5. Next, drop the required data fields from the Field List onto the report’s Detail band, and the OrdersDate field onto the GroupHeader1 band area.

    GroupByTimeSpan_7

    Set the formatting string of the label bound to the OrdersDate field to {0:dddd}. This will make the label only display the day of the week, and not the date. To set the format string of the label, click the label’s Smart Tag, and in the invoked actions list, fill the Format Sorting field.

    GroupByTimeSpan_5

See Also