Working with Groups
Grouping data in a report facilitates business
Crystal Reports provides easy-to-use grouping functionality that enables multiple types of powerful and flexible data grouping. Inserting GroupsTaking either the sample report from this or the previous chapter, you can realize the flexibility and power of grouping in a few short steps. Assume that senior sales management in a hypothetical company is interested in viewing customer order information by Employee/Sales representative, in addition to the existing grouping by Country. The following steps will guide you through an example of how grouping can help this company accomplish this task:
The results of this new grouping are shown in Figure 2.9. Note that the Employee ID grouping is automatically selected to be the
Figure 2.9. Here is a sample report that has been grouped by Country and Employee ID.
Note
The specified order selection of the Insert Group dialog is particularly interesting because of the great flexibility it provides. With this option, you can dynamically create both groups and a custom order of appearance on the report. A
Figure 2.10. The Change Group Options dialog displaying the Specified Order tab.
Another custom ordering option new to XI is the ability to conditionally sort a group based on a formula. This option is enabled through the Group Dialog box and the Use Formula As Sort Order check box. A formula can then be entered by clicking on the x+2 box. A last note on the Change Group Options dialog is that options around group naming are available for customization. These options are accessed through the Options tab and facilitate the process of making your reports most presentable. For example, in another situation you might want to group on a country code instead of a country name for report processing efficiency (that is, numeric fields are sorted faster than string fields), but you still want to present the actual Country Name in the report. You could perform this customization through the Options tab in the Change Group Options dialog as shown in Figure 2.11. Figure 2.11. The Options tab of the Change Group Options dialog enables you to set some custom Grouping options, such as the displayed Group name.
|
|
1. |
Click on the Design tab of the Crystal Reports Designer if you are not already on that tab.
|
|
2. |
After double-clicking and holding the last click on either the Employee ID Group Header or Footer, drag that group to the outside of the Country Grouping to dynamically re-sort the order of grouping. A hand
Tip To facilitate identification of groups while in the Design tab, hover over a group header or footer section and a descriptive rollover tip temporarily appears. |
|
3. |
Click on the Preview tab, and you will see the benefits of your workthe same report with the groupings instantly rearranged. Figure 2.12 highlights your intended results.
Figure 2.12. A sample Customer Orders report regrouped by Sales Rep (Employee ID) and then Country.
Note
Note the change in the Group Tree as you move back to the edited Crystal Report. This Group Tree provides an easy-to-use navigation system for end users of this report as they can drill into the group tree and then link to the exact location and group they
|
An alternative and powerful method for reordering groups is provided with the Group Expert. It is accessed from the Report menu, and the different groups can be reordered through the up and down
Crystal Reports provides an easy method to add multiple groups
This dialog enables the selection of multiple groups in one location and provides access to the same functionality as the Change Group Options dialog through the Options button. The groups can also be easily reordered from within this dialog through use of the up and down arrow buttons, located on the upper right of the dialog area.
One type of grouping that is common across most organizations is
Another type of special grouping that is available in Crystal Reports is hierarchical grouping. This special type of grouping enables your report data to be dynamically grouped on a hierarchy kept within a single table of your database. To enable hierarchical grouping, a group of the base-level data should be created through the standard Group Creation dialogs described previously. The Hierarchical Group option dialog can then be selected from the Report menu. To walk through a quick example, follow these steps:
|
1. |
Create a new blank Crystal Report and connect to the Xtreme Sample Database 11.
|
|
2. |
Select the Employee table for the report and Click on the OK button in the Database Expert.
|
|
3. |
|
|
4. |
Insert a Group on Employee ID using the Insert Group dialog (accessed from the Insert menu) and select ascending sort order. Move to the Options tab of the Insert Group dialog before finishing, click on the Customize Group Name Field check box, and select the Employee Last Name field as the field to display. Now click OK in the Insert Group dialog.
|
|
5. |
Select Hierarchical Grouping Options from the Report menu. You are presented with the dialog displayed in Figure 2.15. Click on the Sort Data Hierarchically option and select either Employee Supervisor ID or Employee Reports To as the parent field with an indent of 0.33 of an inch.
Figure 2.15. The Hierarchical Group Options dialog accessed from the Report menu enables specification of hierarchical grouping options such as parent field and indentation.
|
|
6. |
Click OK and view your new report. Figure 2.16 displays a report that should be similar and highlights the power of hierarchical grouping.
Figure 2.16. A sample report that highlights the hierarchical grouping and indentation functionality.
Caution When creating a hierarchical group, the only eligible parent fields are those fields in the selected data source that have the same field type (for example, number, string, date) as the Grouped On field.
Note As can be seen in Figure 2.16, the value you enter in the Group Indent field affects all other objects in the same report section as your hierarchical group fields. For example, the Position and Extension fields are also indented when you added the Employee field as a hierarchical group with supervisor. With XI, a new function has been added to enable indentation of only the hierarchy records and not the other objects. This is accomplished by leaving this value as 0 (zero) and using the new conditional-X-position feature with the new HeirarchyLevel() function. A sample formula is provided in the Crystal Reports help file and a working sample report is available for download from usingcrystal.com. |