Info

Figure 2-11

Figure 2-11

There are over 20 summary operators available for use, but unfortunately the documentation that ships with Crystal Reports .NET does not include a list of them or how they can be used, so a list of the most popular has been included here. Keep in mind that the summary fields available depend on the type of field you have selected; you can't calculate the average of a string field, for example.

Browse Date .

Summary Function

Description

Sum

Calculates a sum of all items.

Average

Calculates the standard unweighted average for all items.

Maximum

Returns the maximum value.

Minimum

Returns the minimum value.

Count

Calculates the total number of all items.

Sample Variance

Calculates the statistical sample variance of a specific sample of items.

Sample Standard Deviation

Calculates the statistical standard deviation of a specific sample of items.

Population Variance

Calculates the statistical variance of the entire population of items.

Population Standard Deviation

Calculates the statistical standard deviation of the entire population of items.

Distinct Count

Calculates the number of distinct items. For instance, if two different instances of "David" appeared in the list, they would be counted only once.

Correlation

Calculates a measure of the relation between two or more items

Covariance

Calculates a measure of the variance between two or more items.

Weighted Average

Calculates an average, weighted by the number of times an item appears.

Median

Calculates the statistical median of all items.

Nth Percentile

Calculates the Nth percentile, where N is predefined number.

Nth Largest

Returns the Nth largest item, where N is predefined number.

Nth Smallest

Returns the Nth smallest item, where N is predefined number.

Mode

Calculates the statistical mode of all items.

Nth Most Frequent

Returns the Nth most frequent item, where N is a predefined number.

The corresponding functions to these summary fields are also available in the formula language, so you can also use them in complex formulas with branching and control structures if required. Keep in mind that their use as a summary field will be limited only to a few options or parameters passed to each.

Using Analysis Features

In addition to simple summaries (which we have just looked at) and formulas (which are coming up in Chapter 8, "Formulas and Logic"), we also have the ability to add a number of analysis features to our report to help highlight information that may be important or otherwise missed. On the TopN tab of the report expert, we have five options for adding a bit of analysis to our report.

Analysis Type

Description

TopN

Orders your report groups according to a summary field, where you enter a number (N) and are presented with the TopN groups in order from the largest to smallest (for instance, you could create a top 10 report based on last year's sales, to show your best customers). You can also use the options presented to discard the other records or place them in their own group.

BottomN

Will order your report groups according to a summary field, where you enter a number (N) and are presented with the BottomN groups (for instance, you could create a bottom 10 report, based on last year's sales, to show your worst customers). Similar to TopN, you can use the options presented to group or discard the other records.

Sort All

Will order your report groups according to a summary field, either ascending or descending or by a top or bottom percentage, depending on the options you set.

Top Percentage

Will order your report groups according to a summary field, where you enter a percentage (N) and are presented with the Top Percentage of groups (for instance, you could create a Top 10 Percent report, based on last year's sales, to show the customers in the top 10 per-centile). Similar to TopN, you can use the options presented to group or discard the other records.

Bottom Percentage

Will order your report groups according to a summary field, where you enter a percentage (N) and are presented with the Bottom Percentage of groups (for instance, you could create a Bottom 10 Percent report, based on last year's sales, to show the customers in the lowest 10 percentile). Similar to BottomN, you can use the options presented to group or discard the other records.

Keep in mind that all of these analysis options will be applied throughout your report and will apply to any graphs or charts you might insert in the next step of the report expert.

Charting and Graphing

For charting and graphing functionality, Crystal Reports .NET relies on a graphing engine created by 3D graphics. In the report experts as well as the designer itself, you can add a number of different graph types to your report through the Chart tab, shown in Figure 2-12.

Figure 2-12

To create a chart for your report, select the Chart tab, select a chart type, and then select where the data will come from by clicking on the Data tab within the dialog. The most common type of chart is a Group Chart, which requires that both a group and a summary field be inserted into your report. If you would like more information on the different types of graphs, check out Chapter 3, "Designing Reports."

Filtering Your Report

When reporting from a number of different tables, the chances are you don't want to see all of the data in your report. Crystal Reports .NET follows the tradition set in previous versions of the product and has its own Record Selection Formula that dictates what records are returned to the report, so click the Select tab to create the selection formula for your report, as shown in Figure 2-13.

The Record Selection Formula is written using Crystal Reports .NET's own proprietary formula language, which in turn is translated to standard SQL and submitted to the database. When there is a feature that can't be translated to SQL, Crystal retrieves all of the records and uses its own Report Engine to apply the formula and filter the records.

When working with the Select tab in the report expert, the options are identical to those you will find in the Select Expert, which is used inside the Report Designer for record selection.

Figure 2-13

There are a number of basic operators available, depending on the type of field you are working with, including:

□ Is greater than or equal to

□ Is one of - (for building a list of items, such as Is one of Australia, UK, New Zealand; similar to the In operator in SQL)

□ Is like - (for wildcard searches where an asterisk represents many characters — for instance, *Zealand — and a question mark represents single characters — ????Zealand)

□ Is starting with - (for strings that start with a phrase entered)

Remember that this record selection is written to a formula and then translated into the SQL statement. We will look at some more advanced record selection a little later in this chapter and again in Chapter 8, which deals with formulas and logic. For our purposes, we are not going to set any record selection on the report we are creating; we want all of the records to be returned from the sample database, so make sure nothing is in the Select Fields, and move on to the next tab, Style.

Selecting a Report Style

Finally, the last step of the report expert involves selecting a particular style for your report and adding a title using the dialog shown in Figure 2-14. There are 10 different predefined styles to select from and, no, you cannot add your own style to the list! You can also add a report title, in this case Customer Listing Report, which will be stored in the report file's Summary Information. A Report Title field will be added to your report's design. Add a title of Customer Listing Report for this report.

Figure 2-14

Adding Your Report to a Form

The final step in the Standard Expert is to click the Finish button, which will open your report inside the Report Designer within Visual Studio .NET.

Make sure that you get into the habit of immediately saving your report by clicking the Save or Save All icons within the Visual Studio .NET IDE. Although the Report Designer does have an undo feature, it is always nice to have a saved copy in case anything should go wrong.

At this point, you probably want to have a look at how your report will appear when it is printed. Running the report will open only a blank form, though; the designer unfortunately does not include an integrated preview, so to preview your report, you will need to add the Crystal Reports Viewer to a form and then specify the report source to be the report you have just created.

Open Forml.vb in design mode. If you want, you can select the form and then change the text in the properties window to Customer Listing Report, so the user can then see what the report is about if they view the report on a computer. Finally, change the size field so it reads 700,500.

From the Windows Forms section of the Toolbox, drag and drop the CrystalReportViewer onto the form. Without this, any reports cannot be seen. If you can't see the Toolbox, click View ^ Toolbox to make it appear (the keyboard shortcut is Ctrl-Alt-X). Your form should now look something like the form shown in Figure 2-15.

Position the Crystal Report Viewer in the top left corner of the form, and drag its bottom right corner diagonally down, resizing the viewer to fill the whole form. Now when your report is displayed, it is nice and clear. Next, change the anchor property to Top, Bottom, Left, Right so if the form is resized, the Crystal Report Viewer, and more importantly your report inside it, will be resized to match.

Figure 2-15

From the Components section of the Toolbox, drag and drop the ReportDocument icon onto the form. This opens up a dialog like the one shown in Figure 2-16, from which you can choose the report to be opened in the form. Select the report we have just created, displayed as CustomerListing.customerlist-ing, and click OK.

Choose a RejiurlDocument

Choose a typed ReportDocument 'class'.from your project, or the can create one by adding or opening a Crystal R eport

Figure 2-16

The customerlisting.rpt file is now shown in a shaded area at the bottom of the form designer, as shown in Figure 2-17. This shows that the report has been added, and many more reports can be too, using the same method we used here. However, for this example we want to display just the report we have just created, so we will move on.

Was this article helpful?

0 0

Post a comment