Designing reports using BIRT Studio : Filtering data : Creating a filter : Defining multiple filter conditions : How to define multiple filter conditions
 
How to define multiple filter conditions
The following procedure shows how to define multiple filter conditions using Advanced Filter.
1 In BIRT Studio, select the column that contains the values to filter by, then choose Filter.
2 On Filter, choose Advanced Filter.
3 On Advanced Filter, select Static, if necessary.
Advanced Filter displays the selected column in Filter By. To use a different column select a new column from the drop‑down list.
4 Define a filter condition as follows:
1 In Condition, select a comparison operator.
2 Specify a value as follows:
*To type or choose a specific value, choose Specify literal value.
*In Value, type the value, then proceed to step 3.
*To select from a list of values, choose Select Values. A list of values appears. Select a value from the list, then proceed to step 3.
*If the list of values is long, type a value in Filter Text, then choose Find. If found, BIRT Studio highlights this value in the list. Proceed to step 3.
*To compare values in the selected column, to values in another column, choose Use value from data field. Select a column from the drop‑down list. Proceed to step 3.
*To specify a null value, select No Value.
3 Choose Add Condition.
The filter condition appears in the Conditions area.
5 Define the next filter condition on Advanced Filter as follows:
1 In Filter By, select another column.
2 In Condition, select a comparison operator.
3 Specify a value.
*To type or choose a specific value, choose Specify literal value.
*In Value, type the value. Proceed to step 4.
*To select from a list of values, choose Select Values. A list of values appears. Select a value from the list. Proceed to step 4.
*If the list of values is long, type a value in Filter Text, then choose Find. If found, BIRT Studio highlights this value in the list. Proceed to step 4.
*If you choose Use value from data field, select a column from the drop‑down list. Proceed to step 4.
*To specify a null value, select No Value.
4 Choose Add Condition.
In the Conditions area, the second filter condition appears after the first condition, as shown in Figure 5‑12. By default, the second condition is preceded by the logical operator, And.
6 Select a different logical operator, if necessary.
7 If the report contains aggregate data, do one of the following:
*To recalculate aggregate data values across the filtered data rows, select Recalculate Totals if necessary.
*To calculate aggregate data for the unfiltered data, deselect Recalculate Totals.
Figure 5‑12 Advanced Filter displaying two conditions
8 To add additional filter conditions repeat step 4.
9 If you create more than two filter conditions and you use different logical operators, you can use the parentheses buttons to group conditions to determine the order in which conditions are evaluated.
10 Choose Validate to verify the syntax of the filter conditions, then choose Add Filter.
The defined filter conditions appear in the Filters area, as shown in Figure 5‑12. Choose OK.
11 Run the report to verify that it displays the expected results.
Selecting a logical operator
As you add each filter condition, the logical operator And is inserted between each filter condition. You can change the operator to Or. The And operator means both filter conditions must be true to include a data row in the report. The Or operator means only one condition has to be true to include a data row. You also can add the Not operator to either the And or Or operators to exclude a small set of data.
For example, the following filter conditions return only sales data for classic car items for the San Francisco office:
Sales Office = San Francisco
And Product Line = Classic Cars
The following filter conditions return all sales data for the San Francisco and Boston offices:
Sales Office = San Francisco
Or Sales Office = Boston
The following filter conditions return sales data for all product lines, except classic cars, for the San Francisco office:
Sales Office = San Francisco
And Not (Product Line = Classic Cars)
Specifying the evaluation order
BIRT Studio evaluates filter conditions in the order in which they appear. If you define more than two conditions, you can use parentheses to group conditions to get the results you expect. For example, A And B Or C is evaluated in that order, so A and B must be true or C must be true to include a data row. In A And (B Or C), B Or C is evaluated first, so A must be true and B Or C must be true to include a data row. To illustrate the difference a pair of parentheses can make, compare the following examples.
The following filter contains four conditions and none of the conditions are grouped, as shown in the example in Figure 5‑13:
Sales Office = San Francisco
and ProductLine = Classic Cars
and Total >= 5000
or Profit >= 2500
Figure 5‑13 Displaying the results of a filter that does not group conditions
Although the filter specifies the San Francisco office and the Classic Cars product line, the report displays data for other sales offices and product lines.
Without grouped conditions, the filter includes rows that meet either conditions 1, 2, and 3, or just condition 4.
The following filter contains the same four conditions, but this time the third and fourth conditions are grouped, as shown in the example in Figure 5‑14:
Sales Office = San Francisco
and ProductLine = Classic Cars
and (Total >= 5000
or Profit >= 2500)
This time, only two rows meet the conditions. The Sales Office = San Francisco and ProductLine = Classic Cars conditions must be true, and either theTotal >= 5000 condition or the Profit >= 2500 condition is true.
Figure 5‑14 A report displaying the results of a complex filter that uses parentheses to group conditions