Desktop User Guides > Professional > Table scripting > Getting started > Defining your first filter
 
Defining your first filter
Sample script file: MyFirstFilter.mrs
Filters are a quick way of choosing which cases are included in a table. You can define filters using any expression that is supported by the UNICOM Intelligence Data Model.
Table of age by gender, filtered to exclude respondents between 11-16 years
For example, you can create a simple table of age by gender and add a filter to the table like this:
TableDoc.Tables.AddNew("Table1", "age * gender")
TableDoc.Tables[0].Filters.AddNew("Exclude11_16s_A", _
  "Not age.ContainsAny({e1116_years})")
This specifies that the table is to include all of the respondents except those who selected the 11-16 years category in response to the question on which the age variable is based. That is, respondents between the ages of 11 and 16 will not be counted.
Here is the table produced by the script:
This graphic is described in the surrounding text.
There are no respondents in the 11-16 years row. Compare the values in the Base row with those in the Base row in the table that was created in Creating a simple table of Age by Gender: the values in the Base row in the filtered table have been reduced by the values that would have appeared in the 11-16 years row if no filter had been specified.
The filter has been defined using the ContainsAny function that is part of the UNICOM Intelligence Function Library, which comes with the UNICOM Intelligence Data Model. You can also define the filter using the <> comparison operator:
TableDoc.Tables.AddNew("Table2", "age * gender")
TableDoc.Tables[1].Filters.AddNew("Exclude11_16s_B", _
  "age <> {e1116_years}")
For information about the functions that come with the UNICOM Intelligence Data Model, see UNICOM Intelligence Function Library
For examples of using the operators, see Comparison operators.
In the example table, the filter expression is displayed in a header. The header is created automatically as a default annotation. If you give the filter a description, the header shows the filter description instead of the expression. To define a description for a filter, type:
TableDoc.Tables[0].Filters.AddNew("Exclude11_16s_A", _
"Not age.ContainsAny({e1116_years})", "My First Filter")
To change the default annotations or to set up customized annotations for individual tables, see Annotations.
Requirements
UNICOM Intelligence Reporter
Next
More on filters
See also
Getting started