Tutorial 3-10. Formatting Hierarchical Groups
Hierarchical groups (discussed earlier in this chapter) give you the option to customize the indentation level of each child record. This shows a tree-view structure illustrating the relationship between the parent and child records. You can also have them line up directly below each other when there is a limited amount of space on the report. Personally, I don’t think either option is ideal. When indentation is turned on, you have to be sure that the column headers are positioned in a way that makes the data legible even when as it is shifted across the page. In addition to that, when numbers in the same column aren’t right-justified with each other, they are difficult to read. The option to turn off indentation altogether isn’t very practical either because it forgoes using a tree-view structure that makes it easy to quickly understand the relationship between the parent and the child records. So which one should you choose? Both!
Formulas can be used so that you can combine both types of indentation to create professional looking hierarchical reports. What you need to do is indent the text-only fields and right-align up the numeric fields. The reason for indenting the text fields is that they are generally wider and can accommodate the extra space needed for the text to shift from left to right. It also makes it possible to see the parent-child relationship between them. Indentation is turned off just for the numeric columns because people find it easier to read and compare values when the numbers are perfectly lined up with each other.
Crystal Reports lets you customize the indentation of each field using a combination of the functions HierarchyLevel() and GroupLevel(). This lets you indent the text fields but not indent the numeric fields.
Function | Description |
---|---|
HierarchyLevel(grouplevel function) | Returns the hierarchy level of the current group member. This only works for groups that are sorted hierarchically. |
GroupingLevel(field) | Return the group level for the field being printed. Pass it the field that you have a hierarchical grouping on. |
Let’s see the steps to make this work.
- Using a report with hierarchical grouping, open the Hierarchical Group Options dialog box by clicking Report > Hierarchical Grouping Options.
- Set the Group Indent value to 0. This turns off indentation for all columns. The report now looks like a typical columnar report.
- Right-click on a text field and select Object Size and Position. This dialog box lets you set the size of the object as well as its coordinates.
- The X coordinate property controls setting the indentation level so that is the one we want to modify. Click on the Formula Workshop button associated with the X coordinate.
- Enter the following formula:
(HierarchyLevel (GroupingLevel ({Employee.Employee ID})) - 1)*1440/4
This formula calculates the hierarchy level by getting the current grouping level of the current record using the Employee ID field. It multiples it by 1440 (the number of twips per inch) and divides by 4 (to get a quarter of an inch). Each time a child record is displayed, it is offset by ¼ of an inch from the parent record above it.
- Enter the same formula for all text fields that you want to indent.
- When finished entering the formula for all text fields, preview the report and you should see that the text fields are being indented and the numeric fields are aligned with each other. This creates a report which makes it easy to see how the parent and child records are related and still have numeric columns that can be quickly compared and analyzed.
Steps 4 and 5 show you how to use conditional formatting to change the indentation level of a report object using conditional formatting. With Crystal Reports XI R2, you can use the same dialog box to change the width of the report object based upon the data being printed. As you can see in the Figure 3-33, the formula button was added for the Width property.
Formula 3-29. Conditional formatting for object widths (Crystal Reports XI R2).