Skip to main content

Group Data by Days of the Week

  • 3 minutes to read

This tutorial shows you how to group report data by days of the week in the Visual Studio Report Designer. You can use the method described in this topic to group data by month, or by any other time span value.

Group Data by Days of the Week

Prerequisites

Do the following to create a blank report bound to the Orders data table:

  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 menu to invoke the Data Source Wizard, as illustrated in the following image:

    Add Data Source

  3. Create a data source bound to the Orders table in the sample Northwind database. Review the following help topic for more information: Data Source Wizard.
  4. Click Field List in the Visual Studio XtraReports menu to invoke the Field List panel. The panel appears as follows:

    Field List

Create a Calculated Field

  1. In the Field List panel, right-click any data field and select Add Calculated Field in the context menu. Review the following help topic for more information: Calculated Fields.

    Add Calculated Field

    The DataMember property for the created field is set to the Orders table and the calculated field can access data fields from this table.

  2. Right-click the created field and select Edit Calculated Fields:

    Edit Calculated Field

  3. In the invoked Calculated Field Collection Editor, specify the Name property. The DisplayName property is automatically set to the same value.

    Calculated Field Collection Editor

  4. Click the ellipsis button next to the Expression property to invoke the Expression Editor. Enter the following expression in the editor:

    GetDayOfWeek([OrderDate])
    

    The expression returns a zero-based index of the day of the week from the OrderDate data field. For more information on expressions, review the following help section: Use Expressions.

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

    Expression Editor

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

Group by the Calculated Field

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

    Group and Sort panel

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

    Add a Group

    You can use this panel to show or hide the related Group Footer band. For more information, review the following help topic: Group and Sort Panel.

  3. Click Add a Sort and select the OrderID field to sort the displayed data by that field:

    Sort by OrderID

  4. Switch to the Field List and drop the OrderDate data field onto the report’s Group Header band. Drop the OrderID, OrderDate, and CustomerID fields onto the Detail band:

    Drop Grouping Field

  5. In the smart tag menu, click the Format String item’s ellipsis button to change the format string of the label in the Group Header band bound to the OrdersDate field:

    Format Group Label

  6. Set the format string to the {0:dddd} value. This value instructs the label to display the day of the week instead of the date:

    Set Format String

  7. Switch to the Preview tab to see the result:

    Group Data by Day of the Week - Result

See Also