#### Defining filters

To provide flexibility and convenience to end users playing with ad hoc reports, JReport provides two options to narrow down the records:

- Built-in filter: It is defined in JReport Designer for business cubes only and transparent to the end users running the business cube reports.
- Predefined filter: It is predefined on the Designer side for both business and report cubes. Ad hoc end users can choose to apply such filter when designing/modifying reports based on the business/report cube.

##### Defining and applying built-in filters

The following example shows the usage of built-in filters:

1. In the SampleReports catalog, create a business cube called CustomersCube with the Customers table.

   Next, we will create a built-in filter Country='USA' in the business cube.

2. In the Business Cube Editor window, click the Filter button on the toolbar to display the Filter dialog.
3. Click behind the field text box. In the Cube Element Resources dialog, select Country and click OK. See illustration.

4. Select = from the operator drop-down list.
5. Click next to the value text box. In the Values dialog, click the Value sub tab, double-click USA and it will be added to the value box, then close the dialog. See illustration.

6. Click OK to save the filter. The filter is used as a built-in filter in the CustomersCube business cube.
7. Click File > Catalog Management > Save Catalog to save the catalog.
8. Publish the catalog to JReport Enterprise Server.
9. Create reports in JReport Web based on the business cube, the filter will be automatically applied to the business cube, that is to say, the report will get data from USA only.

##### Defining and applying predefined filters

You can also predefine some filters in business/report cubes for ad hoc users to choose when designing/modifying a live report. Let's use the following example to show the basic usage. Note that our example is based on a business cube, the same steps are applied to report cubes as well.

1. Create a business cube called CustomersOrdersCube with the Customers and Orders tables.
2. In the Business Cube Editor window, click the Predefined Filter button on the toolbar to display the Predefined Filter dialog.
3. Click the New button, double-click in the Name cell of the filter and change its name to CustomersFilter, then in the Condition panel, click the Add Condition button and define the filter as Customer ID>=25. See illustration.

4. Click the New button to add another filter and name it OrdersFilter, then define the filter as Shopping Cost=150.
5. Click OK in the Predefined Filter dialog to save the filters.
6. Save the catalog and publish it to JReport Enterprise Server.
7. Create reports based on the business cube in JReport Web, and you can choose which filter you want to apply.

For detailed explanations about how to use the predefined filters in JReport Web, refer to Applying filters to business/report cubes in the JReport Enterprise Server User's Guide.

Notes:

- When the resources that are used in some predefined filters are removed from the business/report cube, the filters will be marked out with an alert in the Predefined Filter dialog. Edit the filters according to your requirements again and the next time you open the dialog, the alert marks will be removed.
- If you want to input values manually in the filter dialogs, pay attention to the following rules:

  String Value

  Rules: Quote the values with single quotes.

  Example1: Customers_Country='USA'.

  Example2: Customers_Country in 'Australia','Germany','Mexico'

  Date Value

  Rules:

  - Default input format supported in JReport Designer is the same as the format of the values available in the Values dialog.
  - Default input format supported in JReport Web is 'MM/dd/yyyy' for Date, 'hh:mm:ss a' for Time and 'MM/dd/yyyy hh:mm:ss a' for Timestamp.
  - Both the above formats are only the input value format in the filter dialogs, and filters are done in the RDBMS side and some RDBMS have special requirements for the date format, so you need to make sure the date formats specified in the Data Format tab of the Get JDBC Connection Information dialog are supported by your database.