Crystal Reports Overview This document explains how to create a columnar report in Crystal Reports (CR). It will also explain how to create drill-down levels in a columnar report. Although this document has been written for CR 9, it applies to earlier versions of CR. If the step-by-step instructions are different in earlier versions of CR, please consult your product documentation or the Crystal Reports Online Help by pressing the F1 key. Contents INTRODUCTION... 2 STANDARD REPORT VS. COLUMNAR REPORT... 2 Standard Design...2 Columnar Design...4 DESIGN A COLUMNAR DRILL-DOWN REPORT... 6 Create a Single Level Columnar Report...6 Add Row Labels to the Report...10 Add Drill-Down Levels to the Columnar Report...12 LIMITATIONS... 14 CONTACTING CRYSTAL DECISIONS FOR TECHNICAL SUPPORT... 15 6/17/2003 9:47 AM Copyright 2003 Crystal Decisions, Inc. All Rights Reserved. 1
Introduction This document explains how to make a report where each column header can be drilled into to show that column s data in a drill-down view. This will occur with the row labels and page headers remaining static. Before beginning, see the Limitations section on page 14. Standard Report vs. Columnar Report Crystal Reports is typically a row-by-row designer. Fields are placed in the Details section and when the report is previewed you will see all the values for a particular record laid out horizontally. There will be as many rows as there are records returned from the database. Standard Design The following explains how Crystal Reports is most commonly used, as a rowby-row report designer. 6/17/2003 9:47 AM Copyright 2003 Crystal Decisions, Inc. All Rights Reserved. Page 2 Figure 1.1 Figure 1.1 shows the Crystal Reports design canvas. It contains two group levels. The first group is on the Customer.Country field and the second is on the Customer.Region field. The report is set up to allow drilling down on Group # 2 and the Details section. This is done by hiding these sections. The report also contains formulas at each level that calculate Premiums, Fee Revenue, Other Income and Total Revenue.
Figure 1.2 When the report is previewed, you will see a separate row for each country within the database. Each row will display the country name and the associated Premiums, Fee Revenue, Other Income and Total Revenue formula values. Figure 1.2 displays the report in Preview mode. The report shows 5 countries, Canada, England, France, Germany and USA. These values have been returned from the database. Each of these countries has its corresponding information displayed in one line reading from left to right along the Preview page. Figure 1.3 As previously mentioned, the report is set up with two groupings and has drill down enabled. Figure 1.3 shows how the cursor icon will change to a 6/17/2003 9:47 AM Copyright 2003 Crystal Decisions, Inc. All Rights Reserved. Page 3
magnifying glass when positioned overtop of a field in a section that can be drilled into. By double-clicking on the object, you will drill into the next level of grouping. Figure 1.4 When the user drills into the next group level, the data is again returned row-byrow. Each region that relates to the country that was drilled down on is returned row-by-row with the corresponding information. Columnar Design This section will explain how to make a columnar report as opposed to the conventional report described previously. 6/17/2003 9:47 AM Copyright 2003 Crystal Decisions, Inc. All Rights Reserved. Page 4
Figure 2.1 Figure 2.1 shows the preview page of a columnar drill report generated from the same database as the previous standard design example. The same five groups have been generated, Canada, England, France, Germany and USA. For each group there are formulas that calculate Premiums, Fee Revenue, Other Income and Total Revenue just as in the previous example. The notable difference between the standard design example and the columnar design example is that the information has been presented in a columnar format. There is a column for each group. The row titles are static and will persist through all levels of drill-down. You still drill down on the group name fields, but the group name fields are now column headers instead of row headers. Figure 2.2 6/17/2003 9:47 AM Copyright 2003 Crystal Decisions, Inc. All Rights Reserved. Page 5
Figure 2.2 displays the drill-down view for the Canada group. As in the previous example of standard design the same Region groups are returned but, like the Country groups in the Preview page, they too are displayed in columnar view. Design a In order to create a columnar drill-down report, you first must create a single level columnar report. Create a Single Level Columnar Report As we have seen, Crystal is a row-by-row designer where the number of rows generated by a report is based on the number of entries in the database being queried. 1. In Crystal Reports, create a new report. On the File menu, click New. Select the As a Blank Report option button then click OK. 2. In the Database Expert dialog box, double-click Create New Connection then double-click ODBC (RDO). In the Data Source Name box click Xtreme Sample Database then click the Finish button. 3. Double-click Tables then double-click Customer. Click OK. 4. On the File menu, click Printer Setup. In the Orientation box select the Landscape option button. Click OK. Using Landscape page orientation allows for more columns per page. 5. On the Report menu, click Edit Selection Formula > Record. Enter the following formula in the Record Selection Formula Editor: {Customer.Country} in ["Canada", "England", "France", "Germany", "USA"] 6. Insert the Customer.Country field into the Details section. Insert a group on the Customer.Country field and suppress both the Details and Group Footer sections. This will give you a Report design similar to that in Figure 3.1 6/17/2003 9:47 AM Copyright 2003 Crystal Decisions, Inc. All Rights Reserved. Page 6
Figure 3.1 When previewed, the report will now show 5 rows - the 5 countries specified in the record selection formula. 7. On the Report menu, click Section Expert. In the Sections window, click Details. Figure 3.2 8. Select the Format with Multiple Columns check box. The Layout tab will appear. 6/17/2003 9:47 AM Copyright 2003 Crystal Decisions, Inc. All Rights Reserved. Page 7
9. Enter 1.000 in the Width text box. Leave the default values (0.000) for the Horizontal and Vertical text boxes and the Printing Direction should be Across then Down. Select the Format Groups with multiple columns check box. Click OK. Figure 3.4 Viewing the design tab of the report, notice the modifications to the report. The Country field is repeated across the Details section in one-inch increments. 10. Increase the height of both Group Header # 1 and Group Footer # 1 to six inches. (see Figure 3.5) This allows for space to insert related fields. If the sections were not heightened the canvas would only have enough room to display the Customer.Country field. 6/17/2003 9:47 AM Copyright 2003 Crystal Decisions, Inc. All Rights Reserved. Page 8
11. Move the Customer.Country field into the Group Footer. Suppress Group Header #1 and unsuppress Group Footer # 1. 12. On the Insert menu, click Summary. From the top drop-down box click Customer ID. From the middle drop-down box click Distinct Count. From the bottom drop-down box click Group # 1: Customer.Country. 13. Insert another summary. From the top drop-down box click Last Year s Sales. From the middle drop-down box click Sum. From the bottom dropdown box click Group # 1: Customer.Country 14. Move the summaries created in steps 12 and 13 below the Customer.Country field. (see Figure 3.5) Figure 3.5 Refresh the report. The five countries that we are working with will now line up, one next to another as will the summaries that you have created. 6/17/2003 9:47 AM Copyright 2003 Crystal Decisions, Inc. All Rights Reserved. Page 9
Figure 3.6 Add Row Labels to the Report The next step in creating the report is to add the row labels that will be seen at each level of drill down. These row titles will be displayed on the far left side of the report and will line up with the records in Group Footer #1. Figure 3.7 6/17/2003 9:47 AM Copyright 2003 Crystal Decisions, Inc. All Rights Reserved. Page 10
1. Increase the height of the Page Header to six inches. 2. On the Insert menu, click Text Object. Place this text object near the top of the Page Header. Type Distinct Count of Customers in this text object. Insert a second text object right below the first and type, Sales Summary in it. 3. Right-click the gray area to the left of the Page Header and then click Section Expert. In the Section Expert dialog box select the Underlay Following Sections check box. If the report were refreshed now the row labels would appear underneath the data. In order to avoid this, we must reserve some canvas space for our row labels. We can reserve this canvas space by using the Group Header section. 4. Right-click the grey area to the left Group Header #1 and click Don t Suppress. 5. Right-click the gray area to the left of Group Header #1 and click Insert Section Below. This will create Group Header #1 b. Increase the height of this section to six inches. Figure 3.8 When the report is previewed (Figure 3.8) the row labels are to the left of the summary fields. Move these fields until they are aligned, as you want. However, there are also large gaps in between the columns that must be removed. 6. Create a new formula and name it SuppressGH1 with the following syntax: whileprintingrecords; numbervar suppressgh1 := suppressgh1 + 1 7. Insert the formula field in Group Header # 1a. Right-click the formula field and then click Format Field. On the Common tab of the Format Editor dialog box, select the Suppress check box. Click OK. 6/17/2003 9:47 AM Copyright 2003 Crystal Decisions, Inc. All Rights Reserved. Page 11
8. On the Report menu click Section Expert. Click Group Header #1 (Be sure to select it as opposed to Group Header #1a or Group Header #1b.) and click the X+2 button next to Suppress. Enter the following syntax: whileprintingrecords; numbervar suppressgh1 > 1 9. Save the formula and preview the report. It will look similar to Figure 3.9. Figure 3.9 Add Drill-Down Levels to the Columnar Report The report is now a columnar report. In this section we will add a drill-down level. 1. On the File menu click Report Options. Select the Show All Headers On Drill Down check box. (Figure 4.1) Figure 4.1 6/17/2003 9:47 AM Copyright 2003 Crystal Decisions, Inc. All Rights Reserved. Page 12
2. On the Insert menu click Group. From the top drop-down box, click Customer.Region. The report designer will add the group level, but it will require formatting to make it compatible with the columnar format. Figure 4.2 3. Increase the height of Group Footer #2 to 6 inches. Suppress Group Header #2 and move the Group #2 Name field to the same position in Group Footer #2 as the Customer.Country field in Group Footer #1. (Figure 4.2) 4. Right-click the gray area to the left of Group Footer #2 and then click Hide (Drill-Down OK). 5. On the Insert menu, click Summary. From the top drop-down box click Customer ID. From the middle drop-down box click Distinct Count. From the bottom drop-down box click Group # 2: Customer.Region. 6. Insert another summary. From the top drop-down box click Last Year s Sales. From the middle drop-down box click Sum. From the bottom dropdown box click Group # 2: Customer.Region. 7. Move these two summary fields below the Group #2 Name field in Group Footer #2 similarly to the summaries in Group Footer #1. The report is now a columnar drill-down report. Preview the report and drilldown on Canada. (When you hover your cursor over a field it will become a magnifying glass icon. Double-click at this point to drill down) You will see the regions for Canada with their summaries. (Figure 4.3) 6/17/2003 9:47 AM Copyright 2003 Crystal Decisions, Inc. All Rights Reserved. Page 13
Figure 4.3 Limitations This design technique will not work if the preview or any drill-down level requires a second page. The first page will look correct but any subsequent pages will have data on top of row labels. For instance, in the example report, drill down on France. The first page of the drill-down level looks correct but if you navigate to Page 2 you will see some groups on top of the row labels. 6/17/2003 9:47 AM Copyright 2003 Crystal Decisions, Inc. All Rights Reserved. Page 14
Contacting Crystal Decisions for Technical Support We recommend that you refer to the product documentation and that you visit our Technical Support web site for more resources. Self-serve Support: http://support.crystaldecisions.com/ Email Support: http://support.crystaldecisions.com/support/answers.asp Telephone Support: http://www.crystaldecisions.com/contact/support.asp 6/17/2003 9:47 AM Copyright 2003 Crystal Decisions, Inc. All Rights Reserved. Page 15