Filtering Report Data with Parameters

Objectives

After completing this lesson, you will be able to:

  • Filter data in a report using single or multiple parameter values.
  • Filter data range in a report using parameters.

Overview of Parameters

Restricting data using a parameter.

Parameters are Crystal Reports fields that you can use in a Crystal Reports formula. As a formula component, a parameter must have a value before the program can process the report. By using parameters in formulas, selection formulas, and in the report itself, you can create a single report that changes its behavior depending on the values entered. Parameter fields can also be used in subreports.

Prompts are elements that help users set a value for report parameters. Prompts are different from parameters in the following ways:

  • Prompts aren't used directly by a Crystal Reports formula.

  • Prompts include user-interface settings that help you determine the appearance of the prompting dialog box that your users see.

  • Prompts include an optional list of values that your users can choose from. This list of values can be a static list that is stored in each report, or a dynamic list that is retrieved from a database (this type of prompt includes multi-level cascading lists that are also retrieved from a database).

  • Prompts can be set so that the parameter itself is optional.

When your users select values in the prompting dialog box, they're setting values for prompts. The Crystal Reports prompting engine then assigns that value to the corresponding parameter, which is finally used by the report. When you create and edit a parameter field, you work with one parameter and one or more prompts.

Once you've created a parameter field, you can use it (or reference it) in your report in place of a fixed value. Many of your reports may be similar to existing reports, but with modifications to the record or group selection. Perhaps the report must be modified to allow for a specific part code, date range, or other value in the record selection. Create a parameter field and use it in your record selection to allow for flexible reporting. When running the report you can choose the part code, date range, or other value you want for this occurrence of the report.

One of the most common uses of a parameter is in record selection (Select Expert).

For example, to easily modify a report for various regions, use a parameter field in place of a specific region value. {Customer.Region} = {?Region} where {?Region} is a parameter field you've created. The value you select for the region parameter field is used for the record selection in that occurrence of the report.

Typical Use Cases for Parameters

Parameters prompt the user of a report to enter information. Think of a parameter as a question that the user must answer before the report is generated. The information users enter, or the way they respond, determines what appears in the report. For example, in a report used by sales people, there may be a parameter that asks the user to choose a region. The report returns the results for the specific region, instead of returning the results for all of the regions.

By using parameter fields in formulas, selection formulas, and in the report itself, you can create a single report that you can modify whenever your needs change.

A parameter field can be identified by braces and a question mark before the parameter name, for example:

{?parameter_name}

Create and Use a Parameter to Filter a Report

Range Parameters

Single and range value parameters to restrict data.

You can create parameters that require users to enter a single (discrete) value, or a range of values. If you include these parameters in your report’s record selection, you can help users find specific information. For example, in the case of a record-selection parameter that uses a discrete value, a user can enter a single country name to see sales figures for only that country. In the case of a record selection parameter that uses a range of values, a user can enter a range of countries (for example, Canada and France) to see sales figures for all the countries in the range (in this case, Chile, China, Denmark, and England).

Note

If the Allow multiple values and the Allow discrete values options are selected, the parameter field will accept multiple single values. In this case, you can enter more than one value, but these values are evaluated individually and will not be interpreted as a range. If the Allow multiple values and Allow range values options are selected, the parameter field will accept multiple ranges.

Filter a Report with a Date Range Parameter

Log in to track your progress & complete quizzes