Viewing: Working with the Ad Hoc Editor > Using Filters

Using Filters and Input Controls

JRXML Topics, Domains, and OLAP connections use different mechanisms for screening the data they return:

   JRXML Topics can contain Parameterized queries. The parameters can be mapped to input controls that allow users to select the data they want to include.

   Domains (and Domain Topics) can be filtered by selecting fields in the Domain and specifying comparison values. The filters can be configured for users to select the data to include.

   Within the Domain design, filters based on conditions can also be defined; these filters are not displayed in the report viewer when the report runs.

   OLAP connections rely on XML schemas to filter the data in an underlying transactional database. Input controls are never generated directly from the OLAP schema.

You can define filters in the Ad Hoc Editor regardless of whether you are working with data from a Domain, Topic, or OLAP connection. Such filters can be helpful in improving the report's initial performance by reducing the amount of data the report returns by default. For more information, see section Input Controls and Filters Availability. To prevent users from seeing the full dataset, you can also use input controls in a JRXML Topic or filters defined in the Domain design, which can be hidden from end users.

If you want to return different data to different users of the same report, define data-level security based on a user roles and profile attributes. This is available for reports based on a Domain, Domain Topic, or OLAP client connection. For more information, refer to the Jaspersoft OLAP User Guide. For more information, refer to section The Domain Security File and to the Jaspersoft OLAP User Guide.

Input controls and filters interact seamlessly. For example, you can create filters in an Ad Hoc View that gets data from a JRXML Topic that includes input controls.

The server refreshes the editor against both the filters and the input controls. Because some combinations of input controls and filters don’t return data, this can result in an empty report.

 

If the result set is empty, check for an incompatible combination of filters and input controls, such as a standard filter (set to Mexico against a Country field) and a Keep Only filter (set to Canada against a Country field), or an incorrectly-defined advanced filter expression (data must meet all criteria in multiple filters, rather than meeting criteria in a subset of those filters). See section Advanced Filtering for information on advanced filter expressions.

In rare cases, filters can conflict with report parameters, and you’ll need to rename the field causing the conflict by editing the JRXML file. Refer to the iReport Ultimate Guide for more information about editing JRXML files.

For more information about:

   JRXML Topics and input controls, see section Adding Input Controls.

   Domain Topic filters, see section Creating Topics from Domains.

   Localizing input control prompts and lists of values, see section Localizing Reports.

Using Filters

Filters can be defined at three levels:

   In the Domain Designer.

   When creating a View from a Domain (in the Data Chooser).

   In the Ad Hoc Editor (even when the View is based on a JRXML Topic or OLAP connection).

In this section, we discuss how to define filters in the Ad Hoc Editor. For information on defining filters in the Domain Designer, see section Pre-filters Tab. For information on defining filters in the Data Chooser, see section The Pre-filters Page.

In addition, you can control how and what filters are applied to a field or fields by using advanced expressions. For more information, see section Advanced Filtering.

To create a filter in the Ad Hoc Editor:

1.     Right-click a field in the Data Selection panel and select Create Filter.

A new filter appears in the Filters panel. If the Filters panel was hidden, it appears when you create a new filter.

 

If the results are empty and you don’t understand why, check for an incompatible combination of filters and input controls. Click to compare input controls with the filters in the Filters panel.

2.     Use the fields in the filter to change its value. Depending on the datatype of the field you selected, the filter maybe multi-select, single-select, or text input.

3.     Click and select Minimize All Filters or Maximize All Filters to toggle expansion of the items in the filter.

4.     Click and select Remove All Filters to remove the filters.

5.     Click to hide the filter’s details. Click to display them again.

6.     Click the Select All check box (if it appears in the Filters panel) to select all values currently available in the dataset. The Select All check box does not appear in the Filters panel for numbers and dates.

Note that the Select All check box doesn’t guarantee that all values are selected every time the report runs. Instead, the check box is a shortcut to help you quickly select all the values currently available in the dataset. To ensure that all values appear in the report whenever it is edited or run, remove the filter entirely. On the panel, you can also create a filter from the right-click context menu of a column in a table. On the Chart tab, you must right-click the field in the Data Selection panel.

When you change a filter, the server uses the new value to determine the data to display. If you change only the operator in a filter, you must deselect the value in that filter, then reselect it to apply the updated filter.

For filters with multiple values, you do not need to reselect all values. After changing the operator, use Ctrl-click to deselect just one of the values, then Ctrl-click to reselect that value.

 

When you right-click a group member in a crosstab and select Keep Only or Exclude, you create complex filters. When you create a filter against an inner group, the filter that appears may be created as a complex filter; a complex filter can’t be edited but it can be removed. Complex filters also appear in the Ad Hoc Editor if a Data Chooser wizard filter was created and locked.

Advanced Filtering

When you create multiple filters, they are, by default, connected with an implicit AND operator; that is, the data displayed in your table, chart, or crosstab is what remains after all your filters are applied.

However, with the advanced filter functionality, you can exercise greater control over the displayed data by applying an advanced expression that includes more complex, nested AND, OR, and NOT operators, as well as by applying multiple filters to a single field.

 

Advanced filters are not available for Ad Hoc reports created from OLAP connections.

Advanced filters are useful in a number of situations, including:

   When using the AND operator isn’t sufficient. Consider an international company that wants to view data for stores located on the Pacific Rim; they may create an advanced expression with the following criteria:

    Country is USA

AND

    State is California OR Washington OR Oregon OR Hawaii OR Alaska.

OR

    Country is Japan OR Indonesia

Using the AND operator for all of these criteria returns an empty View, as no store is located in all of those areas.

   When you need to eliminate some results in a field. For example, if your food and beverage distribution company wants to view sales for all drinks except for high-price items, you might include the following criteria in an advanced expression:

    Product Group is Beverages

NOT

    Price is greater than 39.99

This filter displays all items in the Beverage Product Group, but filters out those with prices over $39.99

These are only two scenarios where advanced filters can hone your results and make your report more precise. There are, of course, many other situations where they can be applied.

In this section, we take you through these tasks:

   Creating an advanced expression

   Editing an advanced expression

   Removing an advanced expression

   Applying multiple filters to a single field

 

Advanced filters are applied to reports, but filter details don’t appear on report previews, or on the report itself.

To create and apply an advanced filter:

1.     Create two or more filters for your data, as described in section See "Using Filters" These can be standard field-based filters, or Keep Only and Exclude filters.

Note that, as you create the filters for use in an advanced expression, you may find that the data in your View disappears, since most (if not all) of the data won’t meet all of the filter criteria. When you create your advanced expression and change some of the ANDs to ORs and NOTs, data reappears in the panel.

2.     At the top of the Filters panel, click in the upper right-corner and select Show Expression to display the Filter Expression, for pane. The Filter Expression, for pane is empty by default.

3.     In the Filter Expression, for pane, click the Edit button. The Edit Advanced Filters dialog appears.

4.     In the Edit Advanced Filters dialog, use the filter preview window to locate the filters, and note the letter designations they have been given.

 

Filter letter designations are case sensitive, and must be CAPITALIZED.

5.     Enter a filter expression using the letter designations, and including the following operators:

    AND narrows your results and includes only fields that meet the criteria of both filters before and after the operator.

    OR broadens your results and includes fields that meet the criteria of either filter before or after the operator.

    NOT excludes results that match the criteria.

    Parentheses combines multiple filters into a single item in the expression.

6.     Check your expression by clicking the Validate button. If your expression works with the available filters, you receive a green “Success” validation message; an incorrect expression receives a red invalid message with a brief description of the problem.

7.     When your expression is validated successfully, click Submit. Your report is updated to reflect the newly-applied filter criteria.

After creating an advanced filter, you may want to add another filter to the expression, or remove one already included in the expression.

 

If the simple filter you wish to delete is part of an advanced filter, you must first remove it from the advanced filter expression; otherwise, deleting the filter deletes the advanced filter expression.

To add a new filter to an existing advanced expression:

1.     If necessary, create the new filter in the Filter panel.

2.     In the Filter Expression, for pane, click Edit to open the Edit Advanced Filters dialog.

3.     In the Edit Advanced Filters dialog, add the new filter to the expression. Any unused filters appear in the filter preview window highlighted in gray.

4.     Click Validate to check the integrity of the new expression.

5.     When your expression is validated successfully, click Submit.

To remove a filter from an advanced expression:

1.     In the Filter Expression, for pane, click Edit to open the Edit Advanced Filters dialog.

2.     In the Edit Advanced Filters dialog, remove the unwanted filter from the expression, and adjust the expression as needed.

3.     Click Validate to check the integrity of the new expression.

4.     When your expression is validated successfully, click Submit.

When working with advanced expressions, you may decide to delete an expression and create a new one.

To remove an advanced expression from a report:

1.     In the Filter Expression, for pane, click Edit to open the Edit Advanced Filters dialog.

2.     Clear the expression from the Filter Expression text box.

3.     Click Submit. The expression is removed, leaving the remaining filters intact.

When you refine your advanced expression, you may also want to delete unused filters from the Filters panel.

   If the filter you want to remove isn’t part of the advanced filter, hover your mouse over in the filter’s title bar and select Remove Filter.

   If you want to remove all existing filters, including the advanced expression, hover your mouse over in the upper right corner of the Filters panhandle select Remove All Filters.

You can apply multiple simple filters to a single field, if needed, to further refine your advanced filter results. For example, a user may want to view the data in the Shipping Cost field, but only when it meets certain criteria combinations:

   When shipping costs to French cities with postal codes that begin with the number 5 are under five Euros

   When shipping costs to German cities with postal codes that begin with the number 1 are under five Euros

 

You can recreate the scenario below using the demo for adhoc topic.

In the following example a user has a table including the following columns:

   Country

   Postal Code

   Shipping Charge

To analyze the specific shipping costs described above, the user creates the following (simple) filters - including two filters each for the Country and Postal code fields:

   A. Country equals France

   B. Postal code starts with 5

   C. Country equals Germany

   D. Postal code starts with 1

   E. Shipping Charge is less than 5

Then, to display only the information she needs, she creates the following advanced expression:

   ((A and B) or (C and D)) and E

This translates to:

   ((FRANCE and POSTAL CODES THAT START WITH 5) or (GERMANY and POSTAL CODES THAT START WITH 1)) and SHIPPING CHARGES LESS THAN 5 EUROS.

Using Input Controls

In the Ad Hoc Editor, you can display the input controls defined in the Topic as visible to users. You can accept the controls’ default values or enter other values. The Ad Hoc Editor indicates that the View has input controls by displaying as active on the tool bar. Click this icon to select new values or to save values as the new defaults for this report. The following procedure steps through these tasks.

To add an input control to the report using a filter:

1.     Create a new filter, or use an existing one in the Filters panel.

2.     In Filters, click beside the new filter, and select Show Operator.

The filter’s operator appears in a drop-down.

3.     Select an operator from the drop-down and enter the in the text box below the drop-down.

The filter appears as an input control when the View is used to run the report.

4.     Place your cursor over , select Save Ad Hoc View as....

5.     Name the report, select a location, and click Save.

6.     On the tool bar, click .

Only the input controls defined in the topic appear here. Again, if no input controls were defined in the topic, the button appears inactive. You can create a report and open it in the Report Viewer to see a filter listed as an input control.

To edit the values for a View’s input controls:

1.     On the tool bar, click .

A window listing the input controls defined in the Topic appears.

 

The Parameterized Report Topic already includes three input controls, created when the report was uploaded: Country, RequestDate, and OrderId.

2.     Select new values. For example, select USA from the Country drop-down.

3.     To change default values of input controls, select the check box, Set these values as defaults when saving your View.

The selected values become the default values when you save the View.

4.     Click OK.

The report design on the Ad Hoc View shows USA data.

Input Controls and Filters Availability

Input controls and filters can appear in the Editor and when a report runs:

   Input controls can be set to be visible or invisible when you edit a report:

    Input controls set to Always prompt are displayed in the editor and always appear before the report is run.

    Input controls that aren’t set to Always prompt are always hidden in the editor and hidden when the report is run.

   Filters defined in the Domain design are always hidden in the editor and when the report is run.

   Filters created in the Data Chooser wizard can be locked or unlocked:

    Filters that are unlocked display filter information in the editor and are available from the Options button when the report is run.

    Filters that are locked display input controls in the editor when you click to see the View in display mode but are not available from the Options button when the report is run. Users can remove the filter while in the editor, allowing them to see all the data unfiltered when the report is run.

    You can’t change whether the filter is displayed after the report is created.

   Filters defined in the editor are always available in the Filters panel of the editor and from the Options button when the report is run.

When setting up input controls for a huge report that takes a long time to run, consider setting the report to Always prompt. Before a report is run, the Report Viewer prompts you to provide the input options, preventing the report from running using the default input options.

Filters that are unlocked are available. When input controls or filters don’t appear in the Report Viewer, click the Options button to view them. You can learn more about how filters and input controls interact in the editor by walking through the data exploration tutorial with the Filters panel open.

To set an input control to always prompt:

1.     Locate a Topic, such as the Parameterized Report Topic, in the repository and click Edit.

2.     On the Controls & Resources page of the JasperReport wizard, under Input Control Options, select Always prompt:

To determine whether an input control is visible:

1.     Locate a Topic, such as the Parameterized Report Topic, in the repository and click Edit.

2.     On the Controls & Resources page, click the name of an input control, such as Country.

3.     On the Locate Input Control page, click Next.

At the bottom of the Create Input Control page, if the Visible check box is selected, the input control appears on the report when it runs. For more information, see section Adding Input Controls.

 

If you don’t provide a default value for the input control, users are prompted to select a value when they create a report based on the Topic.

To lock a filter:

1.     Click Create Ad Hoc View.

2.     In the Data Chooser wizard, click Domains to create a new report based on a Domain.

3.     Click Choose Data.

4.     In Fields, move tables and fields from Source to Selected Fields.

5.     Click Pre-filters.

6.     Double-click a field in the Fields panel.

7.     In the Filters panel, define a filter as described in section The Pre-filters Page.

8.     Check the Locked check box, and click OK.

9.     Click Table to open the Ad Hoc Editor.

In the Filters panel, the name of the filter and a note about the lock appears under the heading Locked.