Pages

Tutorial: Working with Specified Grouping

Grouping within Crystal Reports is an easy way to organize like records. In this tutorial, learn how to use "specified grouping" to re-order your report data and make it easier to understand.

Note: This tutorial refers to the Xtreme Sample Database, which is a sample database used by Crystal Reports. If you don't have a copy of this database, you can download it from here. You will need to setup an ODBC driver to point to this database.

Grouping is often used to help analyze report data, as it can draw a clearer picture of what is in the data. For example, you could create grouped report that would show records by state, so all of the sales for a particular state would be shown together.

But what if you want to group on an item not found in the database? Or if you want to re-order the data? Crystal Reports provides a feature called "specified grouping" that will allow you to create your own custom groups to display the data as you like.

In this tutorial, we will look at how to create a specified group using some of the sample data that ships with Crystal Reports. We will create an "Employee Listing" report that shows the country where employees live and then we will create a specified group to group these countries into "North America" and "Europe" respectively.

1. Open Crystal Reports 2008 from the Start menu

2. Select File > New to create a new Standard Report

3. Under "Available Data Sources", double-click the option for "Create New Connection" and double-click "ODBC (RDO)" to open the standard ODBC dialog.

4. Select "Xtreme Sample Database" and click Finish to return to the Standard Report Wizard.

5. Expand the "Tables" section and double-click to select the "Employee" and "Employee_Addresses" tables and then click "Next" to continue.

6. The next step of the wizard is for specifying the links between the two tables. In this instance, both tables have a common key and the link has already been created for you, so you can click "Next" to continue.

7. In the next dialog, select the fields for your report-- to select a field, highlight it in the list on the left and then click the right-arrow button to move it to the list on the right. Select the following fields:

Employee.First Name
Employee.Last Name
Employee.Position
Employee_Addresses.City
Employee_Addresses.Region
Employee_Addresses.Country

And click "Finish" when you are done. You will end up with a simple listing report that matches the fields you have selected.

8. Next, we are going to insert our group-- select the Insert menu then "Group" to open the Insert Group dialog.

9. Using the first drop down list, select the Employee_Addresses.Country field and in the second drop-down box, select "In Specified Order"

10. This will change the dialog to show a "Specified Order" tab. In the text box marked "Named Group" enter the names of your groups, pressing enter after each. In this example, we are going to create two groups-- "North America" and "Europe"

11. Once you have entered these two groups, click to select the "Europe" group and click "Edit"

12. In the dialogue named "Defined Named Group" change the drop-down list to "Is one of" and select the countries of "UK" and "France" and click OK. Repeat this same action with the "North America" group, adding "Canada" and "USA"

Note:
You may have noticed there is also an "others" tab that specifies what will occur when there is a country that does not meet the criteria you have specified. Use the options on this tab to set whether these records will be shown in their own groups, a custom-named group or not shown at all.

13. When you have finished editing your specified groups, click OK to return to your report, which should now show the two groups of "North America" and "Europe" as well as an "Others" group if you took the default settings.

You can use this technique anywhere you have a group inserted into your report.

No comments:

Post a Comment