Grouping data hierarchically
Characteristics of the data needed for hierarchical grouping
You can group data in a report to show hierarchical relationships. When you group data hierarchically, Crystal Reports sorts information based on the relationship between two fields. A hierarchical relationship must be inherent in the data that you use for the report:
-
Parent and child fields must be of the same data type for the program to recognize a relationship between them.
-
The data in the parent field must be a subset of the data in the child field.
-
For the top level of a hierarchy to appear in a report, the value must appear in the child data, and the corresponding row in the parent data must be empty.
-
There cannot be any circular logic in the data (that is, A cannot be related to B, while B is related to C, and C is related back to A).
For example, if you want to show the hierarchical relationship of the people who work in a department, you could group data by employee name (the child field) and specify the hierarchy by using the field that lists whom the employee reports to (the parent field). Your database tables might look like the following example.
|
Employee (child) |
Supervisor (parent) |
|---|---|
|
Jane |
Thomas |
|
Mina |
|
|
Gerard |
Thomas |
|
Albert |
Thomas |
|
Thomas |
Mina |
|
Beth |
Thomas |
|
Teresa |
Thomas |
|
Gareth |
Thomas |
|
Valerie |
Thomas |
|
Gillian |
Mina |
|
Frances |
Gillian |
|
Ruth |
Gillian |
|
Margaret |
Mina |
|
Paul |
Margaret |
|
Charles |
Margaret |
The Employee and Supervisor fields contain overlapping data that implies a hierarchical relationship. There are 15 unique employee names, with four of these names also appearing as supervisors (Mina, Thomas, Gillian, and Margaret). Three employees report to Mina, seven employees report to Thomas, two employees report to Gillian, and two employees report to Margaret.
If you group a Crystal report on the Employee field, you can further sort the data to show the hierarchical relationship between these employees and their supervisors.
Characteristics of a report that you have grouped hierarchically
In addition to a visual representation of the hierarchy inherent in your data, a Crystal report that you have grouped hierarchically has several other characteristics:
-
When you drill down on a group in the hierarchy, the drill-down view also shows the records that are lower in the hierarchy.
-
The report contains hierarchical group footers that include the records that are lower in the hierarchy of each group. You can summarize data across the hierarchies.
-
Use the conditional-X-position feature to ensure that the indenting you set to show hierarchical relationships does not affect other fields in same section of your report.
-
Hierarchical levels are supported in the formula language through the use of the GroupingLevel and HierarchyLevel functions.