Lesson 2: Creating and Modifying Reports 51
Figure 2-46 Preview Sample Results
When the preview is initially generated, only the records necessary to populate the first page are retrieved
from the data source. For this reason, the total number of pages is unknown until the last page of the
preview has been generated. This is why the page count window shows the of total number of pages number
with a plus sign (+), to indicate that the total number of pages has yet to be determined.
Figure 2-47 Preview Page Count Indicator
To navigate through the data, click the Show Next Page or Show Previous Page buttons to
advance or regress one page through the report. To navigate to the beginning or the end of the report, click
the Show First Page or Show Last Page buttons.
Copyright ©2017 Pathfinder Learning, LLP
52 Lesson 2: Creating and Modifying Reports
If changes have been made to the underlying data and need to be represented in the report, click the Refresh
button or hit the F5 key on the keyboard. If data is taking an unacceptable length of time to retrieve, and
you are content with examining the data that has been successfully transferred to the report, click the Stop
button to cancel the Refresh.
Figure 2-48 Navigation Toolbar
Locally Stored Data
When a report has been successfully previewed, the retrieved data is stored on the designer’s local computer.
This allows future report modifications to be performed with greater speed and improved response time. As
stated before, if the data becomes stale, refresh the data to retrieve the most current records from the data
source.
Crystal Reports will automatically refresh the data if one of the below listed events occurs:
Additional fields are added to the report
Criteria (i.e. filter settings) has changed that would require previously unselected records to be
included in the report
A formula utilizing a previously unselected field is created
Crystal reports will not automatically refresh the data when a saved file is opened. If the data should always
reflect the most current version of the data source, the Refresh step can be automated by requiring the data be
automatically updated upon opening of the file. This setting can be found under File – Options – Reporting
tab – Discard Saved Data on Open.
Figure 2-49 Option Dialog Box
Copyright ©2017 Pathfinder Learning, LLP
Lesson 2: Creating and Modifying Reports 53
Exercise 2-7 Previewing and Navigating Report Data
This exercise will demonstrate techniques used to preview data. You will also gain experience with report
navigation.
1. Continuing on with the My Shipping Orders file from the previous exercise, click the Print Preview
button on the Standard toolbar.
2. Use the Page Navigation buttons to advance and regress through the report.
3. Navigate to the end of the report to discover the total length of the printed report.
4. Click View and select Preview Sample.
5. Select First and enter 10 in the records field. Click OK
6. Observe how the report is limited to the first ten records in the data source.
7. Return to viewing all report data (repeat Step 4 but set the Preview this report with: control to All
records and click OK.
8. Save the My Shipping Orders file.
9. Close the file.
Copyright ©2017 Pathfinder Learning, LLP
54 Lesson 2: Creating and Modifying Reports
Challenge Exercise – Basic Report
Create a report that lists the Supplier’s information.
1. Click File > New > Blank Report OR on the Start Page, under the START A NEW REPORT banner,
click Blank Report.
2. In the Database Expert window, open the My Connections folder and choose the Northwind 2008
database connection.
a. Expand the category labeled Tables.
b. Select the table named Suppliers.
c. Click OK.
3. Add a Text Object to the left edge of the Report Header section.
a. Click inside it and type Suppliers.
b. Click outside the text object then click the text object to select it.
c. Format the text as Bold, 16 pt.
d. If needed, make the Report Header section taller: hover the mouse cursor over the bottom of that
section and drag down.
4. Add the following fields to the Details section: SupplierName, Address, City, Region, Phone. If
needed, reduce the length of the Phone field so it fits.
5. Browse the phone numbers; notice their varied lengths and formatting.
6. Position the fields so they look good to you.
7. Save the report as My Suppliers.
Copyright ©2017 Pathfinder Learning, LLP
Lesson 2: Creating and Modifying Reports 55
8. Preview the report, it should resemble the image below.
Figure 2-50 Preview of Suppliers Report
Bonus tip: How to keep the report header title centered even if the title text changes?
Resize the Report Header’s text object so it stretches from the left margin to the right margin.
Center the text. Change the text to List of Suppliers; the title should still be centered.
Figure 2-51 Design view of Report Header text object stretched between margins
Copyright ©2017 Pathfinder Learning, LLP
56 Lesson 3: Formatting Number-based Fields
Lesson 3: Formatting Number-based Fields
Unit time: 75 minutes
In this lesson, you will be introduced to:
1 Formatting Introduction
2 Accessing the Formatting Options for a Field
3 Formatting Numbers
4 Formatting Currency
5 Formatting Date and Time
Copyright ©2017 Pathfinder Learning, LLP
Lesson 3: Formatting Number-based Fields 57
Formatting Introduction
When working with data sources and reports, it is traditional to store numbers in one format while displaying them in
a different format. To reduce redundancy in the data, characters like commas, percent signs, and dollar signs are not
stored as part of the data. Only at the time of presentation are these symbols added to make a report easier to read.
In an attempt to take care of some of the formatting of numbers, Crystal Reports attempts to determine the purpose of
the number and format the number accordingly. Unfortunately, this feature is rather hit-or-miss in its accuracy. It is
important to know how to format numbers so the reader of the report interprets the numbers correctly.
Copyright ©2017 Pathfinder Learning, LLP
58 Lesson 3: Formatting Number-based Fields
Accessing the Formatting Options for a Field
Formatting options for a field can be accessed by either of the following methods:
Click the Format dropdown menu and select Figure 3-1 Format from Dropdown Menu
Format Field… The field you want to format must
be selected before the Format Field option is
available.
Right-click on a field and select Format Field…
Figure 3-2 Format from Right-Click Menu
Copyright ©2017 Pathfinder Learning, LLP
Lesson 3: Formatting Number-based Fields 59
Formatting Numbers
From either the Design tab or the Preview tab right-click on the field containing numeric data and select Format
Field… This will launch the Format Editor.
Figure 3-3 Format Editor Dialog Box (Number)
The Format Editor is where all of the cosmetic changes to data is controlled. There are several tabs across the top of
the dialog box. Each tab controls a different aspect of the field’s presentation. Although some features are unique to
Crystal Reports, many of the features work the same as with any application dealing with the presentation of data.
The following is a table that briefly describes the purpose of each tab in the Format Editor along with descriptions of
some of the more widely used features.
Tab Title Purpose
Common The Common tab contains controls for the basic functionality of the majority of objects
in Crystal Reports.
Border
Object Name: Customizing the name of an object
Read Only: Prevent formatting of the object through other tools
Lock Position and Size: Prevents relocating or resizing of the object
Suppress: Hides the field from preview or other report printing
Can Grow: Defines the maximum height a field may grow
Text Rotation: Enable rotation of objects
Horizontal Alignment: Aligns data within the field
The Border tab provides formatting for the borders, background, and drop-shadows.
Line-Style: Solid, dashed or dotted lines for all sides of an object
Border Color: The color applied to the borders
Background Color: the interior color of the object
Drop Shadow: Adds the illusion of depth to an object
Copyright ©2017 Pathfinder Learning, LLP
60 Lesson 3: Formatting Number-based Fields
Tab Title Purpose
Font The Font tab provides formatting for font style, size and color as well as making a font
bold and/or italic.
Number The Number tab enables the application of various predefined number styles. Advanced
customization allows you to define currency symbols along with characters used as
thousands separators, rounding, and the setting of decimal precision.
Hyperlink The Hyperlink tab is used to create hyperlinks to other files, email addresses, websites,
as well as other reports or objects within the current report.
Table 3-1 Format Editor Tabs
In addition to the controls featured throughout the Format Editor, more advanced customization can be performed by
clicking the button on the Number tab. From here, decisions regarding the displaying of zero
values, currency symbols, thousands separators, rounding, leading zeroes, and the way in which negative numbers
will be displayed can be controlled.
Figure 3-4 Customize Style Dialog Box
Copyright ©2017 Pathfinder Learning, LLP
Lesson 3: Formatting Number-based Fields 61
Formatting Currency
Due to the data redundancy that would be incurred by storing currency symbols in the data, those symbols are
traditionally added when representing the data in a report. This is done by virtue of number style formatting
instructions.
The ability to define not only the symbol used when representing currency, but the position of the symbol gives the
report designer great flexibility when designing a report.
Currency symbols can also take the form of fixed or floating.
Fixed Currency Symbol Floating Currency Symbol
Figure 3-5 Fixed Currency Format Figure 3-6 Floating Currency Format
Accessing the formatting controls for currency is done with the same techniques as numbers.
The Format Editor dialog box contains the same tabs as when formatting numbers. From here you can decide
whether to show or hide the currency symbol as well as decide on the fixed/floating behavior of the symbol.
Figure 3-7 Currency Symbol Controls
Copyright ©2017 Pathfinder Learning, LLP
62 Lesson 3: Formatting Number-based Fields
More extensive customization may be applied by clicking the button. This will display the same
options that are available to numbers while also allowing currency symbol manipulation.
Figure 3-8 Additional Currency Symbol Controls
Copyright ©2017 Pathfinder Learning, LLP
Lesson 3: Formatting Number-based Fields 63
Formatting Date and Time
Date and time information is typically stored together; the whole number portion represents the date and the
fractional portion of the number represents the time. If no time information has been stored in the original data
source, Crystal Reports will add the time of midnight (12:00am) to the date. It is not uncommon for a report to only
focus on the day that a transaction took place and not be concerned with the time. For this reason, it is sometimes
necessary to prevent the display of time information.
Accessing the formatting controls for dates and times is done with the same techniques as numbers. The Format
Editor dialog box has the same tabs of controls as when manipulating number fields, with the exception of the
Number tab; this tab has been replaced with the Date and Time tab.
Figure 3-9 Format Editor Dialog Box (Date and Time)
Copyright ©2017 Pathfinder Learning, LLP
64 Lesson 3: Formatting Number-based Fields
The Date and Time tab contains a variety of ways of displaying date and time information. If deeper customization
is required, click the button to access the following controls:
Figure 3-10 Custom Style Dialog Box – Date Tab
Figure 3-11 Custom Style Dialog Box – Time Tab
Copyright ©2017 Pathfinder Learning, LLP
Lesson 3: Formatting Number-based Fields 65
Exercise 3-1 Formatting Number-based Fields
In this exercise, you will have the opportunity to access various customization options for improving the
appearance of numbers, dates, times, and currency values.
1. Browse to the location of the saved class files and open the folder named Exercise Files\Lesson 03.
2. Select the E3-1 Order Details file and then click Open.
3. Preview the report by clicking the Preview tab.
4. Observe the various issues with the formatting of the numbers.
a. OrderID does not need a comma separator
b. CustomerID does not need a comma separator or two decimal precision
c. OrderDate needs to have the time portion removed
d. UnitPrice needs a U.S. currency symbol (ensure UnitPrice is set to two decimal precision)
e. Quantity needs to display the whole number portion only
Figure 3-12 Number Format Problems
5. Return to the Design view by clicking the Design tab.
6. In the Details section, right-click on the OrderID field and select Format Field…
7. In the Format Editor dialog box, on the Number tab, in the Style section, select the appropriate number
format -1123. This will remove the comma separator and show the whole number portion only.
8. Click OK.
9. Perform steps 6 and 7 on the CustomerID field.
10. In the Details section, right-click the OrderDate field and select Format Field…
11. On the Date and Time tab, select the date option with the March 01, 1999 format.
12. Click OK.
13. In the Details section, right-click the UnitPrice field and select Format Field…
Copyright ©2017 Pathfinder Learning, LLP
66 Lesson 3: Formatting Number-based Fields
14. On the Number tab, check the box for Display Currency Symbol
15. Click OK.
16. In the Details section, right-click on the OrderID field and choose Format Painter .
If you wish save time when applying the same number style to another field, click the field that has the
design you like, then click the Format Painter button on the Standard toolbar. Your pointer will
display a paint brush next to the standard text select pointer. Click on the field you wish to receive
the formatting styles.
17. In the Details section, click on the Quantity field.
18. Switch to the Preview Tab.
19. Verify the report is similar to the image below.
Figure 3-13 Exercise 3-1 Results
20. Save the file as My Order Details.
21. Close the file.
Copyright ©2017 Pathfinder Learning, LLP
Lesson 3: Formatting Number-based Fields 67
Challenge Exercise - Formatting
In this exercise,you will create an Order Shipping report.
1. Create a new report.
2. In the Database Expert window, open the My Connections folder and choose the Northwind 2008
database connection.
a. Expand the category labeled Tables.
b. Select the table named Orders.
c. Click OK.
3. In the details section, add the fields: CustomerID, OrderAmount, OrderDate, ShippedDate,
ShipName and ShipCity.
4. Add a report title Order Shipping. Format it as you wish.
5. Save the report as My Orders Shipping.
6. Format the fields:
a. CustomerID as no decimals and no commas.
b. OrderDate as a date in the format mm/dd/yyyy.
c. Change ShipName column heading to Ship to Name (customer).
d. ShippedDate as a day of week, short version, a dash and m/d/yyyy.
i. To format ShippedDate with the day of the week, right click on the ShippedDate and click
Format Field.
ii. In the Format Editor, click Customize…
Figure 3-14 Format Editor
Copyright ©2017 Pathfinder Learning, LLP
68 Lesson 3: Formatting Number-based Fields
iii. Choose Date from the Order dropdown.
Figure 3-15 Custom Style
iv. Click the Date tab. For Day of Week, choose Short. To add a dash between the day and the
date, click in prefix and type space, dash, space, then click OK. Click OK again.
Figure 3-16 Custom Style
Copyright ©2017 Pathfinder Learning, LLP
Lesson 3: Formatting Number-based Fields 69
7. Preview the report, it should resemble the image below.
Figure 3-17 Challenge Exercise Results
Copyright ©2017 Pathfinder Learning, LLP
70 Lesson 4: Grouping, Sorting and Filtering
Lesson 4: Grouping, Sorting and Filtering
Unit time: 75 minutes
In this lesson, you will be introduced to:
1 The Importance of Grouping Records
2 Sorting Records with the Record Sort Expert
3 Filtering Records with the Select Expert
4 Creating Group Summary Calculations
5 Calculating Percentages in Summaries
6 Sorting Groups According to Subtotal Rankings
Copyright ©2017 Pathfinder Learning, LLP
Lesson 4: Grouping, Sorting and Filtering 71
The Importance of Grouping Records
If you have ever looked at a long list of records and thought to yourself, “This would be much easier to read if the
records were collected together by ‘x’ or by ‘y’ ”, then you have just identified the need for groups. Grouping
records helps the report reader to focus on specific areas of the data, allowing them to reach a decision more quickly.
Creating groups by department, by state, or by product makes information easier to read as well as easier to compare.
Groups can also be totaled and the individual group records hidden to produce a summary report that makes it easy to
compare products against one another.
The Group Expert
The Group Expert is used to create groupings within your report by which you can view subtotals and sort
the report data. For example, let us assume that you were requested to create a report that shows employees
sales with totals by employee. Oftentimes, when you state the purpose of the report you will notice that you
wish to see the data “by” some field. The word “by” is often an indication of which field you will want to
use to create the groups in your report. When you create groups based on the value of a field, Crystal
Reports will group together all of the exact same values found within the selected field. You can then
perform additional calculations over the groups established, like sum the value of an Amount Sold field for
each unique grouping of values in an Employee ID field. Grouping by data fields makes these types of
summary calculations possible.
In Crystal Reports, you can use the Group Expert dialog box to create the groupings necessary for your
report. You can launch the Group Expert dialog box by either clicking the Group Expert button in the
Experts toolbar or by selecting Report, Group Expert… from the Menu Bar.
Figure 4-1 Group Expert from Report Dropdown Menu
Copyright ©2017 Pathfinder Learning, LLP
72 Lesson 4: Grouping, Sorting and Filtering
In the Group Expert dialog box, click on the name of the field by which you want to create the first group in
the Available Fields: list. Then click the greater than button to move the selected field over into the
Group By: list on the right.
Figure 4-2 Group Expert Dialog Box
If you wish to create a multi-level group, you can then click on another field in the Available Fields: list and
click the greater than button to move it to the Group By: list. Note that the sub-groupings appear indented
below the previous grouping above them. If you wish to remove a field by which you are grouping within
the Group By: list, click on its name on the right to select it and then click the less than button .
Once fields have been added to the Group By: list on the right, if you decide that the order should be
rearranged (ex: Salesperson by Region should be Region by Salesperson), select the field to be repositioned
and click either the up arrow button or down arrow button located in the upper-right of the Group
Expert dialog box.
Figure 4-3 Group Expert Hierarchy Controls
Copyright ©2017 Pathfinder Learning, LLP
Lesson 4: Grouping, Sorting and Filtering 73
You also can set the properties of the data fields in the Group Expert dialog box. Just click on the field for
which you want to set grouping options in the Group By: list, and then click the Options… button at the
bottom of the list.
Figure 4-4 Group Expert Options
This will launch the Change Group Options dialog box.
There are two tabs here which you can use to set the group properties: the Common tab, and the Options tab.
Change Group Options – Common Tab
If you click on the Common tab, you will be presented with the name of the field by which the
groupings will be created displayed in a drop-down box. Below that you have another drop-down
that displays the four different options that you have for sorting data. You can select to sort the
groups in either
Ascending order (AZ, 110)
Descending order (ZA, 101)
Original order (the order as they appear in the database)
Specified Order
Figure 4-5 Change Group Options Dialog Box – Common Tab
Copyright ©2017 Pathfinder Learning, LLP
74 Lesson 4: Grouping, Sorting and Filtering
If you select the in specified order option, you will see a new tab added to the Change Group
Options dialog box named Specified Order.
Figure 4-6 Change Group Options Dialog Box – Specified Order Tab
Here you can create a specified order by which to sort the groups that is neither ascending nor
descending but rather based on queried logic about the data. A simple example might be to classify
any state with a population less than 1 million as Small, any state with a population greater than 10
million as Large, and all other states as Medium. This technique is covered in greater detail in
subsequent training classes.
Back on the Common tab it is worth noting that if you have a date field selected for the grouping,
then you will also see another drop-down appear under the listing of The section will be printed:.
Figure 4-7 Change Group Options Dialog Box – Date Grouping
Copyright ©2017 Pathfinder Learning, LLP
Lesson 4: Grouping, Sorting and Filtering 75
Here you can choose the date grouping that you wish to use for your selected field. If you have a
logical (Boolean) value selected for the grouping, then you will see a drop-down that gives you
options for creating groups based on the logical values.
Figure 4-8 Change Group Options Dialog Box – Boolean Grouping
Finally, you can click on the Options tab to set other available options for the grouped field.
By default, the group name fields have the same values as the group field. You can check the
Customize Group Name Field checkbox to specify the group name field as either a database field
or a group name formula that returns a string (text) value that can be used for the group name field.
For example, you could group by the Employee ID field, but display the Employee Name for the
group field name. This would make your report easier to understand since most readers would be
familiar with the employee’s name and not as familiar with the employee’s number.
If you wanted to, you can also choose the Use a Formula as Group Name option and then click the
X+2 button to create a text formula that you can use for the values. This technique is covered in
greater detail in subsequent training classes. You cannot choose to customize the group name at all
for fields that are sorted in specified order.
You can also check the Keep Group Together checkbox to try to keep the groups that are created
from breaking across multiple pages, if possible. Use this feature when you are relatively certain the
groups will be small; i.e. groups containing low number of records. If this feature is engaged and the
first group in the report extends beyond the boundary of the first page, the entire group will be
moved to the following page resulting in a blank first page of the report.
You can check the New Page After checkbox to create a new page after a specified number of
visible groups have appeared. You can also check the Repeat Group Header on Each Page
checkbox to allow groups that do break across multiple pages to repeat the group header information
for each page.
Copyright ©2017 Pathfinder Learning, LLP
76 Lesson 4: Grouping, Sorting and Filtering
Once you have set any options for the selected field by which you are grouping, click OK in the
Change Group Options dialog box to return to the Group Expert dialog box. Then click the OK
button in the Group Expert dialog box to apply the selected groupings to the report.
Figure 4-9 Change Group Options Dialog Box – Options Tab
Copyright ©2017 Pathfinder Learning, LLP
Lesson 4: Grouping, Sorting and Filtering 77
Normally when you create field groupings in reports, you will see a new group tree pane at the left
of the report that you can use to jump to the various sections of the report.
Figure 4-10 Group Tree
You will also typically have a group header and group footer where you can see the names of the
groups in your report.
Figure 4-11 Group Header and Group Footer Section Titles
As stated earlier, when you create groupings within a report, Crystal Reports will then create a
Group Header and a Group Footer for each field by which you grouped both above and below the
Details section in the Design View of the report. If you have added multiple fields by which you are
grouping, then you will see multiple group headers and footers, labeled Group Header #1:, Group
Copyright ©2017 Pathfinder Learning, LLP
78 Lesson 4: Grouping, Sorting and Filtering
Header #2:, and so on and so forth. Also, Crystal Reports will add the group name (as you specified
it when setting the options) to the Group Header sections. Remember that data placed into the
Group Header will repeat at the top of each unique value within the group that was created, and data
placed into the Group Footer will repeat at the end of each unique value in each group.
An alternative approach to creating groups is to click the Insert Group button on the Insert
toolbar. This is an ideal method of creating groups when you are grouping by one of the fields
contained in the Details section. By selecting the field to be grouped first, then clicking the Insert
Group button, you are taken directly to the logical options and controls of the Change Group
Options dialog box.
Copyright ©2017 Pathfinder Learning, LLP
Lesson 4: Grouping, Sorting and Filtering 79
Exercise 4-1 Grouping Records with the Group Expert
This exercise will provide you with experience using the Group Expert tool.
1. Browse to the location of the saved class files and open the folder named Exercise Files\Lesson 04.
2. Select the E4-1 Completed Orders file and then click Open.
3. Save the file as My Completed Orders with Groups.
4. Switch to the Design tab if necessary.
5. Remove the ShipCity and ShipRegion from the Details section.
6. On the Experts toolbar, click the Group Expert button.
7. From the Available Fields: list on the left, add the following fields to the Group By: list on the right:
a. Orders.ShipCountry
b. Orders.ShipRegion
c. Orders.ShipCity
8. Click OK. Crystal Reports creates a separate group header and group footer for each of the selected
fields.
9. To make it easier to understand the hierarchical relationship between ShipCountry, ShipRegion, and
ShipCity, slightly indent the Group #2: ShipRegion field in the Group Header #2 section. Indent the
Group #3: ShipCity field in the Group Header #3 section further to the right of Group #2;
ShipRegion.
Figure 4-12 Group Hierarchy
10. Click Preview.
Copyright ©2017 Pathfinder Learning, LLP
80 Lesson 4: Grouping, Sorting and Filtering
11. Verify the report is similar to the image below. (showing page 18 of the report)
Figure 4-13 Exercise 4-1 Result
12. Save the My Completed Orders with Groups file.
13. Close the file.
Copyright ©2017 Pathfinder Learning, LLP
Lesson 4: Grouping, Sorting and Filtering 81
Sorting Records with the Record Sort Expert
Loading data and creating a report is all well and good, but if the data’s structure has no apparent rhyme or reason, it
may as well not exist. The ability to locate specific records by key criteria is critical for prompt and effective
decision making.
Locating the top sale in a report with hundreds, perhaps thousands of sales transactions can take an inordinate
amount of time if the data is not sorted properly. If sales are presented in chronological order, yet you are interested
in finding the largest sale, that sale could exist anywhere in the report. It would be useful to be able to examine the
report based on other criteria, such as sales amount or shipping region.
Figure 4-14 Data Sorted by OrderID
To sort your data by any criteria in the report, click Report and select Record Sort Expert… or click the Record
Sort Expert button on the Experts toolbar. This will produce a dialog box where single or multiple sort criteria
may be defined.
Figure 4-15 Record Sort Expert Dialog Box
Copyright ©2017 Pathfinder Learning, LLP
82 Lesson 4: Grouping, Sorting and Filtering
The process is relatively straight forward; select the field you wish to sort from the window on the left, then click the
greater than button in the middle of the dialog box to move the selected field to the window on the right. If
you accidentally add a field to the right side that you do not intend to use, click the field in the right-side window and
click the less than button to remove the unneeded field from the sort selection.
Figure 4-16 Record Sort Expert with Criteria
To assign specific sort logic to each field separately, click the field name in the right window, then click either
Ascending or Descending from the Sort Direction control.
Figure 4-17 Sort Direction Control
Each selected field will display either an “A - ” or a “D - ” prefix to denote its currently set sort direction.
Figure 4-18 Sort Direction Prefix
Copyright ©2017 Pathfinder Learning, LLP
Lesson 4: Grouping, Sorting and Filtering 83
To arrange the precedence order of the sort criteria, select the appropriate field in the Sort Fields window and click
either the Promote or Demote buttons to position the field at the proper level.
Figure 4-19 Sort Priority Controls
Copyright ©2017 Pathfinder Learning, LLP
84 Lesson 4: Grouping, Sorting and Filtering
Exercise 4-2 Sorting Records with the Record Sort Expert
This exercise will demonstrate how to use the Record Sort Expert to create multi-level sorts with data. You
will also see how to alternate the sort logic from one sort level to another.
1. Browse to the location of the saved class files and open the folder named Exercise Files\Lesson 04.
2. Select the E4-1 Completed Orders file and then click Open.
3. Save the file as My Completed Orders Sorted.
4. Switch to the Design tab if necessary.
5. Click the Record Sort Expert button on the Experts toolbar.
6. Select the following table fields and place them in the proper order with the defined sort direction:
a. Orders.ShipRegion (Ascending)
b. Orders.ShipCity (Ascending)
c. Orders.OrderID (Descending)
7. Click OK.
8. Switch to the Preview tab to verify the sort results.
9. Click the Record Sort Expert button on the Experts toolbar.
10. Remove Orders.ShipRegion from the Sort Fields list.
11. Click OK to observe the new sort results.
12. Return the sort result back to the original sort order (by OrderID) by either moving the OrderID field to
the top of the sort list or removing the ShipCity field. Remember to change the sort order from
descending to ascending.
Copyright ©2017 Pathfinder Learning, LLP
Lesson 4: Grouping, Sorting and Filtering 85
13. Verify your report is similar to the image below.
Figure 4-20 Exercise 4-2 Result
14. Save the My Completed Orders Sorted file.
15. Close the file.
Copyright ©2017 Pathfinder Learning, LLP
86 Lesson 4: Grouping, Sorting and Filtering
Filtering Records with the Select Expert
The ability to only display records from the data source that meet specific criteria is one of the great strengths of
Crystal Reports. Filtering is the process by which you select only the data that is relevant to the report being created
and ignoring data that is not relevant. Imagine if when connecting to a data source you were required to bring into
your data model every transaction with every bit of data for each record. The end result would be reports where the
conclusions to the report would be buried or hidden within pages of irrelevant information.
The Stages of Filtering
Filtering is performed in stages. Although it is not required that every stage be executed, in most reports,
performing all three stages is common.
Stage One – Table Selection
Table selection filtering is performed when you select just certain tables from a database, ignoring
other tables. When a database contains multiple tables, it is likely that data in some of the tables are
not relevant to your report. We have seen that by selecting the tables that contain only the fields of
interest, we can provide greater focus to the finished report.
Figure 4-21 Selecting Tables with the Database Expert
Copyright ©2017 Pathfinder Learning, LLP
Lesson 4: Grouping, Sorting and Filtering 87
Stage Two – Field Selection
Field selection filtering occurs when the report designer selects specific fields in a table to add to the
report. Any field not added to the report is ignored which in turn reduces the amount of non-relevant
information the reader of the report must process. Although fields not directly added to the report do
not display their transactional data, unused fields may still be used for grouping, sorting, and
calculation purposes.
Figure 4-22 Selecting Fields with the Field Explorer
Stage Three – Record Selection
A report that contains every record for the selected table/fields will inevitably contain more data than
is necessary. The ability to display only those records that conform to defined criteria is paramount
when developing effective reports. Focusing the reader’s attention will save both time and effort
when reaching business decisions.
Select Expert Filter Methods
The primary tool used to filter records is the Select Expert. The Select Expert can filter data by way of three
methods:
Record Filtering
Filtering by record is the most common form of filtering. The process is simple; select the field
containing the data you wish to filter, define the filter operator to qualify records you wish to
display, then define the criteria that those records will be judged against.
Filtering by record is the only filtering method that generates Structured Query Language (SQL)
syntax that is used for database evaluation.
Copyright ©2017 Pathfinder Learning, LLP
88 Lesson 4: Grouping, Sorting and Filtering
By using the SQL instruction, Crystal Reports only pulls records from the database that conform to
the query rules. This reduces the time required to update the report as well as reducing the size of
the cached data within the report.
This course will focus on the record filtering method.
Group Filtering
Filtering by group accomplishes the same objective of a record filter; the difference being that a
group filter is exercised on already retrieved data. Group filtering allows you to store all of the
records contained in the selected tables, then filter them in-place. This provides the ability to
perform multiple passes of filters on the locally stored data without the need to refresh the data from
the data source.
Saved Data Filtering
Filtering with saved data (introduced in Crystal Reports 2008) works the same way that group filters
work, but with the additional assistance of parameters (not covered in this course.) Parameters allow
the designer to select from pre-defined filter criteria to manipulate the selected records without a live
connection to the data source. This is especially useful when performing offline querying of data
contained within a report.
Implementing Record Filters with the Select Expert
There are several methods by which record filters can be implemented:
From the Report dropdown menu, click Select Expert… then select Record…
Click the Select Expert button from the Experts toolbar.
Right-click on a field in the Details section and click Select Expert Record…
Copyright ©2017 Pathfinder Learning, LLP
Lesson 4: Grouping, Sorting and Filtering 89
When no field is selected, launching the Select Expert tool displays the Choose Field dialog box.
Figure 4-23 Choose Field Dialog Box
The Choose Field dialog box displays hierarchies of fields currently in use by the current report as well as all
fields from all currently targeted data sources. Once a field is selected for filtering, clicking OK will display
the Select Expert – Record dialog box.
Figure 4-24 Select Expert – Record Dialog Box
The initial state of any filter is to display all records in an unfiltered state. The operator is any value ensures
no filters are exercised on a particular field. Time can be saved by selecting the field in advance of
launching the Select Expert. This will allow the Select Expert to assume that filtering is to perform on the
selected field and this will bypass the Choose Field dialog box and move directly to the Select Expert –
Record dialog box with the selected field targeted for filtering.
Copyright ©2017 Pathfinder Learning, LLP
90 Lesson 4: Grouping, Sorting and Filtering
The following table lists all of the possible operators as well as an explanation for their use. Be aware that
certain operators are only listed when querying certain data types (i.e. Boolean data types.)
Operator Filters
Is any value No filter being applied. All records are displayed. This is the default.
Is equal to
Is not equal to Displays records that exactly match the value you specify.
Is one of
Is not one of Displays records that are not an exact match to the specified value.
Is less than
Is less than or equal to Displays records that exactly match a list of values specified.
Is greater than
Is greater than or equal Displays records that are not an exact match of any values specified.
to
Is between Displays records with a value less than the value specified.
Is not between
Displays records with a value less than or equal to the value specified.
Starts with
Does not start with Displays records with a value greater than the value specified.
Is like
Displays records with a value greater than or equal to the value
Is not like specified.
Is in the period Displays records with a value between the two values specified.
Is not in the period Displays records with a value that is not between the two values
specified.
Is true Displays records that have the same initial characters specified.
Is false
Formula: Displays records that do not have the same initial characters specified.
Table 4-1 Select Expert Operators Displays records that match the character pattern specified. You
establish the pattern using the wildcard characters of the question mark
and/or the asterisk.
Displays records that do not match the character pattern specified. You
establish the pattern using the wildcard characters available.
Displays records that have a date/time value that falls within the
date/time period specified.
Displays records that have a date/time value that does not fall within the
date/time period specified.
Displays records where the logical (Boolean) value is true.
Displays records where the logical (Boolean) value is false.
Used for selecting all records that match the result of a formula that you
specify.
Copyright ©2017 Pathfinder Learning, LLP
Lesson 4: Grouping, Sorting and Filtering 91
Once an operator has been selected, the Select Expert will display a list of the first 500 unique entries from
the targeted field. This limit of 500 unique field entries is adequate for lists like U.S. States or corporate
departments, but may not provide a full list of certain fields, like part numbers or dates. If the item you are
wishing to filter by is not listed, simply type the entry directly into the dropdown box. The Select Expert
will execute the filter regardless of the input method.
Figure 4-25 Select Expert Displaying Possible Options for Field Filtering
Copyright ©2017 Pathfinder Learning, LLP
92 Lesson 4: Grouping, Sorting and Filtering
Exercise 4-3 Filtering Records with the Select Expert
In this exercise, you will gain experience with filtering records as well as gaining insight as to when data
need to be updated based on report modifications.
1. Browse to the location of the saved class files and open the folder named Exercise Files\Lesson 04.
2. Select the E4-3 Orders Shipped by Location file and then click Open.
3. Save the file as My Orders Shipped by Location Filtered.
4. Switch to the Preview tab and observe the record count on the Status Bar at the bottom of the screen.
Figure 4-26 – Status Bar Record Count
5. Ensure that no fields are selected in the report. On the Experts toolbar, Click the Select Expert
button.
6. From the Choose Field dialog box, scroll down to select ShipCountry from the Orders table and click
OK.
Figure 4-27 Choose Field Dialog Box
Copyright ©2017 Pathfinder Learning, LLP
Lesson 4: Grouping, Sorting and Filtering 93
7. In the Select Expert – Record dialog box, select is equal to from the operator dropdown, then select
USA from the criteria dropdown.
Figure 4-28 Record Select Expert Dialog Box
8. To view the formula generated by the Select Expert, click the button. You may
need to click Hide Formula first.
9. After you have viewed the formula for filtering the country field by USA, click the OK button to invoke
the filter.
10. The system will prompt for a refresh of the currently cached data. Since the current data cache contains
all of the USA records, a refresh is not necessary. Click the button to view
the results of implementing the filter.
Figure 4-29 Record Update Prompt
Copyright ©2017 Pathfinder Learning, LLP
94 Lesson 4: Grouping, Sorting and Filtering
11. Verify your report is similar to the image below.
Figure 4-30 Exercise 4-3 Result
12. Leave the file open for the next exercise.
Copyright ©2017 Pathfinder Learning, LLP
Lesson 4: Grouping, Sorting and Filtering 95
Filtering Records with Multiple Criteria
There are times when multiple criteria need to be applied to produce the desired filter result. The Select
Expert can accommodate compound criteria when filtering records. To define additional filter criteria, either
click the tab or click the button in the Select Expert – Record dialog box. When
defining multiple criteria in the Select Expert, each individual criteria is placed on a separate tab in the Select
Expert - Record dialog box.
Figure 4-31 Record Select Expert Query Tabs
Be advised that all additional filters are logically connected to the previous filters with AND logic; meaning
that a record must match all filter criteria in order to qualify for inclusion in the finished report.
Modifying Existing Filter Criteria
To make changes to existing filter criteria, activate the Select Expert and click on the tab containing the
criteria to be modified.
Once the appropriate filter criteria has been selected, make any necessary changes and click OK to
implement the new filter criteria.
Deleting Filter Criteria
Once the criteria has been selected, click the button to remove the tab from the Select
Expert – Record dialog box. Click OK to implement the modified filter criteria.
Changing Multiple Filter Criteria Logic
As previously stated, multiple filter criteria are logically joined by means of AND logic. This is useful when
you wish to display multiple countries or multiple shipping IDs. There will be times when you may wish to
use OR logic to filter records.
In our example, suppose you wish to view all USA records from the Country field regardless of Shipper ID,
and all records with a Shipper ID of 2 regardless of the originating country. This would require OR logic
instead of AND logic.
Copyright ©2017 Pathfinder Learning, LLP
96 Lesson 4: Grouping, Sorting and Filtering
To implement such a filter, create the country and shipper ID filters as previously instructed. Once the filters
are in place, click the button to display the SQL query code (if not already
displayed.) The syntax will look similar to the below image.
Figure 4-32 Record Select Expert Query Logic
In the syntax window located in the bottom portion of the Select Expert – Record dialog box, replace the and
with or. Because of the nature of this modification, it is a good idea to refresh the data.
Since the report is now displaying all records from the country USA and all records with a Shipping ID of 2,
more records will qualify for the report.
Copyright ©2017 Pathfinder Learning, LLP
Lesson 4: Grouping, Sorting and Filtering 97
Exercise 4-4 Filtering with Multiple Criteria
This exercise will provide you with experience filtering data by criteria as well as creating compound filters
for filtering by multiple criteria.
1. Continuing on with the My Orders Shipped by Location Filtered file from the previous exercise, on
the Experts toolbar, click the Select Expert button.
2. Click either the tab or click the button in the Select Expert - Record dialog
box to create a new filter.
3. From the Choose Fields dialog box, select OrderAmount from the Orders table and click OK.
4. From the Operators dropdown list, select is greater than or equal to.
5. In the criteria box, type 1000 and click OK.
6. Since all the records that conform to the new compound filter are already present in the local cache, it is
not necessary to refresh the data from the data source. Click the button to
implement the new filters. The report now displays all records from USA with an order amount of
$1,000 or more.
7. Because the two filters are working together under the logic of an AND, the report length will be greatly
reduced. To view all records that apply to either filter criteria, click the Select Expert button.
8. If the formula code is not visible in the Select Expert – Record dialog box, click the
button.
9. In the formula in the lower portion of the dialog box, change the and to an or, then click the OK button.
Figure 4-33 AND Formula Changed to OR Formula
Copyright ©2017 Pathfinder Learning, LLP
98 Lesson 4: Grouping, Sorting and Filtering
10. Because OR criteria always results in a greater number of records that qualify for the filter, it would be
wise to refresh the data. Click the button. The report now displays all
records from USA as well as all records with an order amount of $1,000 or more.
11. Verify your report is similar to the image below.
Figure 4-34 Exercise 4-4 Results
12. Save the My Orders Shipped by Location Filtered file.
13. Leaave the file open for the next exercise.
Copyright ©2017 Pathfinder Learning, LLP
Lesson 4: Grouping, Sorting and Filtering 99
Exercise 4-5 Deleting Filter Criteria
This exercise will demonstrate how to remove filter criteria.
1. Continuing with the My Orders Shipped by Location Filtered file from the previous exercise, on the
Experts toolbar, click the Select Expert button.
2. In the Select Expert – Record dialog box, select the Orders.OrderAmount tab.
3. Observe that it is not possible to remove the filter by clicking the button. This is due
to the fact that the formula has been manually adjusted (per the previous exercise). Once a formula has
been manually adjusted, only new filters can be created via the dialog button controls. Deletions can
only be performed by manually highlighting and deleting the applicable portion of the formula.
4. Remove the or {Orders.OrderAmount} >= $1000.00 portion of the formula (don’t overlook the OR
portion of the formula)
5. Click OK to implement the updated filter criteria.
6. Select to update the report.
7. Verify your report is similar to the image below. The report should now include only records from USA
regardless of order amount.
Figure 4-35 Exercise 4-5 Results
8. Save the My Orders Shipped by Location Filtered file.
9. Close the file.
Copyright ©2017 Pathfinder Learning, LLP
100 Lesson 4: Grouping, Sorting and Filtering
Creating Group Summary Calculations
Once report data has been grouped, sorted, and possibly filtered, the report viewer will likely require that the
resultant data be summarized. Summaries produce subtotals and grand totals throughout the report. Summaries are
created by clicking the Insert Summary button on the Insert toolbar or by right-clicking on a field and selecting
Insert Summary… from the submenu.
Figure 4-36 Insert Summary Dialog Box
Keep in mind that summaries are based on the existence of groups. If you attempt to insert a summary calculation
and there are no groups present in your report, Crystal Reports will prompt for a field upon which to base its
calculation and then add the calculation to the end of the report as a grand total. During the creation of the summary,
you may define groups at this point in time with the button. In addition to creating the groups,
summary calculations will also be created for each group.
Copyright ©2017 Pathfinder Learning, LLP