Learn Tables : Filters
Last Updated on Wednesday, 13 July 2011 08:22 Written by Admin Wednesday, 13 July 2011 08:22
In the previous article we looked at how to tabulate the questions in our survey. When we create tables it is often that we don’t want to tabulate all the data but a subset of it. In this article we will look at how we can create those sub sets of data so that we can filter our tables at the global level or at the table level.
In this example we will use the first five tables from our previous set of tabulations
oTableDoc.Tables.AddNew("Table1", "age", "Table1")
oTableDoc.Tables.AddNew("Table2", "* age", "Table2")
oTableDoc.Tables.AddNew("Table3", "age * before", "Table3")
oTableDoc.Tables.AddNew("Table4", "age * before > gender", "Table4")
oTableDoc.Tables.AddNew("Table5", "age * before + gender", "Table5")
Once we have made our script work with these tables we will make a filter that effects all the tables. To check our filter has worked we need to , before we apply the filter , check the totals of our tables. So in our case we check Table 1 and see what the base figure is for it.
for us , before the filter is applied, we can see the base is 602. So what does the filter look like , well type the following code above table 1 and we will explain.
oTableDoc.Global.Filters.AddNew("Filter1", "gender.ContainsAny({Male})")
oTableDoc.Tables.AddNew("Table1", "age", "Table1")
As you can see the syntax is easy to read. On our tables document at the global level we have added a new filter called “Filter1″ which pulls out all the people that ticked male at the gender question. And when you run the script you will see the base for all the tables as gone down and in our case is has gone down to 339
so that is creating a filter at the global level , but how do we create one at the table level. Well basically we use the same syntax, add the following under table4
oTableDoc.Tables.AddNew("Table4", "age * before > gender", "Table4")
oTableDoc.Tables["Table4"].Filters.AddNew("Filter1", "gender.ContainsAny({Female})")
This time we don’t add the filter to the global object but we add it to the table object. With the tables object we have supplied the table name that we want to apply the filter to by placing the name inside the braces,
oTableDoc.Tables["Table4"] ...
and then with the filter object we use the AddNew method to add our filter which in this case filters all the respondents that ticked female at the gender question. When we run this table we will see that table4 has a zero base. This is because the filter we have just added is added to the globals filter so it means that we will only see the records that have clicked male and female at the gender question. Which because the gender question is single response all the records are filtered out.
So hopefully now you have enough information to create your tables and apply the filters to get the results you need. In our next article we will look at the different export options that we have available.


