Crystal Reports  

Grouping Data Hierarchically

You have the option to group data in a report to show hierarchical relationships. When you group data hierarchically, you sort information based on the relationship between two fields.

For example, if you want to show the hierarchical structure of a department, you could group data by employee ID and specify the hierarchy using the data field listing whom the employee reports to.

To group data hierarchically

  1. Right-click in the Crystal Reports ActiveX Designer, point to Insert and click Group.
  2. In the Insert Group dialog box, select the field to be the basis of your hierarchy.

    For example, if you want to view the hierarchical structure of a company's employees, select the employee ID data field. If you want to view the hierarchical structure of region sales offices, select office names.

  3. Select in ascending order.

    By default, the group header of the report will display the value of the field you are grouping on.

  4. Click the Options tab and select the Customize Group Name Field check box if you want to show a different value in the group header.

    If you want to display a different value (employee name instead of employee ID), customize the group name field by choosing an alternate data field, or creating a formula.

  5. Click OK.

    The group you created is added to the report.

  6. Right-click in the Crystal Reports ActiveX Designer, point to Report, and click Hierarchical Grouping Options.
  7. In the Available Groups list, select the group you want to organize hierarchically.

    If you've created only one group in your report, it is automatically selected in the Available Groups list.

  8. Select the Sort Data Hierarchically check box.
  9. In the Parent ID field list, select the field by which you want the Instance ID field organized.

    For instance, for a company hierarchical report, you might select the data field listing the supervisor to whom the employee reports.

    Note   The Instance ID and Parent ID fields must be of the same data type. For example, if the Instance ID field holds string data, then the Parent ID field must also hold string data.
  10. In the Group Indent field, enter the amount you want to indent for each subgroup.
  11. Click OK.

The report data is now grouped hierarchically. If necessary, you can now calculate summary fields across your new hierarchical grouping. When inserting a Subtotal, Grand Total, or Summary in the usual manner, select the "Sum across hierarchy" option.

Tip   If you want to suppress the group header, right-click the group header and click Format Section. Click the Suppress check box.
Note   The top level of the hierarchy is determined by group instances that match the Instance ID and Parent ID. If a group instance is not connected to any Parent ID, it appears at the top of the hierarchy.

See Also

Totaling Data