Chapter 10 - Creating Cross-Tab Reports


Cross-tab reports are a powerful way to create summaries of data in a spreadsheet style format. They generate summary data in a grid where the rows and columns represent groups of data. This provides the user with a report format that is easy to read and uses a small footprint on the page. After this chapter you should have a good understanding of how to use cross-tab reports and you'll also get some practice with creating them.

Become a Crystal Reports expert with the authoritative resource available. The tuturials and tips in this book will take your skills to the next level.
Buy at

This is an excerpt from the book Crystal Reports Encyclopedia. Click to read more chapter excerpts.

Tutorial 10-5. Customizing the Column Grouping

Rather than formatting the cross-tab object based upon the data within the report, you can also let the reader decide how to customize the cross-tab. By integrating parameters within the cross-tab, the user gets to choose how the cross-tab is designed.

This tutorial customizes the cross-tab by modifying the grouping column. The report first asks the user whether they want to group by year or by quarter. The cross-tab changes the column data based upon the user’s response.

  1. Open the CrossTab.rpt sample report that was installed with Crystal Reports. Save it as CrossTab Using Parameters.rpt.
  2. The first step is to create the parameter that prompts the user for how they want the cross-tab printed. Create a new parameter by going to the Field Explorer window, right-clicking on the Parameter Fields item and selecting New.
  3. For the parameter name, enter Cross-Tab Grouping.
  4. For the List of Values, leave it at the default value of Static.
  5. Use the Insert button to create two new parameters3: “Group by Quarter” and “Group by Year”.
  6. For the Options listed at the bottom, set Allow Custom Values to False.
    Now that the parameter is created, we need to create a formula that uses that parameter to set the date format and then we’ll use this formula in the cross-tab object.
  7. Make sure you are on the Design tab and right-click on the top left corner of the cross-tab object and select Cross-Tab Expert from the pop-up menu.
  8. Click the New Formula button and name the formula Date Grouping.
  9. Enter the following formula using Crystal syntax.
  10. if {?Cross-Tab Grouping} = "Group By Quarter" then
    CStr({Orders.Order Date}, "yyyy") & " - Q" & CStr(DatePart("q", {Orders.Order Date}), 0)
    else
    CSTR({Orders.Order Date}, "yyyy")

    This formula checks what the user entered for the parameter value. If it is “Group By Quarter”, then the date is formatted to show the year and then the quarter. If not, then just the year is shown.
  11. Click the Save and Close button to save the formula and check for errors.
  12. Since the formula uses a parameter, you are prompted to set the parameter value. Choose the Group By Quarter option.
  13. On the Cross-Tab Expert dialog box, select the Date Grouping formula in the Available Fields window and click on the right-arrow button for the Columns list.
  14. Within the Columns list, we want to remove the Orders.Order Date field that was previously there. Select on that field and click the left-arrow button to remove it from the list. The only field that should be left in the Columns list is the Date Grouping formula.
  15. Click the Ok button to close the Cross-Tab Expert dialog box.
  16. Click on the Preview tab to look at the report. In an earlier step you already selected Group by Quarter for the parameter value. So the report should look similar to the Figure 10-ae.
  17. Figure 10-ae. Cross-Tab with grouping by quarter.

  18. If your report looks fine, then press the F5 key to refresh it and prompt for a new parameter value. Select Group By Year and your report should look similar to the following:

Figure 10-af. Cross-Tab with grouping by year.

In this example we used parameters to customize the cross-tab. This let the user decide how the Order Date should be grouped. You can use parameters within formulas to let your users customize cross-tab reports in a variety of ways.
To read all my books online, click here for the Crystal Reports ebooks.