ActiveReports 8 > ActiveReports User Guide > Concepts > Page Report Concepts > Grouping Data (Page Layout) |
In a page report, you can set grouping to organize data in your reports. The most common grouping scenario is to create groups by fields or expressions in a data region.
Depending on the data region you select, you can group data in one of the following ways:
See Grouping in a Data Region for further information.
Note: In this topic, the data displayed in the screenshots is from the Movie table available in the Reels database. By default, the Reels.mdb file is located in the [User Documents folder]\ComponentOne Samples\ActiveReports 8\Data folder. |
In a fixed page layout, you can also group data on a report page. See Grouping in a FixedPage for further information.
Detail grouping is available in the List and Table data regions. It is useful when you do not want to repeat values within the details. When you set detail grouping, the value repeats for each distinct result of the grouping expression instead of each row of data.
For example, if you use the Movie table of the Reels database to display movie titles by year without setting detail grouping, you see each year as many times as there are movies from that year.
If you set detail grouping to =Fields!YearReleased.Value, each year appears only once.
Note: If the detail grouping expression you use results in a value that is distinct for every row of data, MovieID for example, you will see no difference in the results. |
If you want to display parent-child relationships in your data, you can create a recursive hierarchy. To do this, you need a unique ID field for the child group and an ID field for the parent group.
For example, if you have pulled data from the Reels database using the following SQL query:
SQL Query |
Copy Code
|
---|---|
SELECT EmployeePosition.*, Employee.*, Employee_1.PositionID AS ManagerPosition FROM Employee AS Employee_1 RIGHT JOIN (EmployeePosition INNER JOIN Employee ON EmployeePosition.PositionID = Employee.PositionID) ON Employee_1.EmployeeID = Employee.ManagementID; |
You can set Detail Grouping in a Table data region using the =Fields.Item("EmployeePosition.PositionID").Value
field, and the =Fields!ManagerPosition.Value
field as the parent group to display parent-child relationships in your data.
Note: You can use only one group expression when you set a parent group. |
To better visualize data in a recursive hierarchy, you can use the Level function. This function indents text and further clarifies the relationships between parent and child data. To do this, you set an expression in the Padding - Left property of the text box you want to indent.
For example, in a Table data region, for the recursive hierarchy example above, you can set the following expression in the Padding - Left property of the text box that contains the Title to indent values according to levels:
=Convert.ToString(2 + (Level()*10)) & "pt"