This article describes how to create a complicated filter with nested conditions in Displayr. Filters can be created out of any of the below data types:
- Numeric ranges
- Single and multiple-response categories
- Aggregated and calendar date period ranges
- Text content
In this example, we wish to create a filter for the following set of group conditions:
- Males under 35 (Nominal crosstab)
- Number of Coca-Cola cans/bottles drunk while out and about is greater or equal to 5 (Numeric)
- Aware of any Coke brands (Binary - Multi)
OR:
- Interviewed after 1/1/2012 (Date/Time)
- Preferred cola is a Coke brand (Nominal)
OR:
- Mentioned EITHER Coke OR Coca-Cola for Spontaneous Awareness (Text)
Requirements
- A Displayr document containing a data set.
- A set of variables to be included in a filter.
Method
1. In the toolbar go to Anything > Filter > New.
2. Select the x for the first condition next to Please select data on the right as we will instead be using group conditions.
3. At the top change ALL of these conditions are met to ANY.
4. Select Add Group.
5. Select the Age variable.
6. Select Gender for Column data to produce a crosstab.
7. Tick the first 3 categories in the Male column.
On the right will appear the number of selected respondents for this filter condition:
8. Select Add Condition.
9. Select Coca-Cola - When 'out and about'.
10. Set the drop-down to is greater than or equal to and enter the value of 5.
11. Select Add Condition.
12. Select the Awareness variable.
13. Tick the Coke brands and leave the setting as is any of.
14. Select Add Group.
15. Select Interview Date.
16. Set the drop-down to is after and change date to 1/1/2012.
17. Select Add Condition.
18. Select the Preferred cola variable.
19. Tick the Coke brands.
20. Select Add Group.
21. Select the Spontaneous Awareness: 1st mention text variable.
22. Leave setting as contains but enter Coke in the box.
23. Select Add Condition.
24. Select the Spontaneous Awareness: 1st mention text variable.
25. Leave setting as contains but enter Coca-Cola in the box.
26. Change ALL of these conditions are met to ANY for this group.
27. Update Specify conditions to generate a default name... at the very top to Coca-Cola Segment. If you don't provide a label, Displayr will create one based on your conditions. For example: (Age/Gender is 18 to 24 & Male, 18 to 24 & Female, 25 to 29 & Male, 25 to 29 & Female, 30 to 34 & Male or 30 to 34 & Female and Coca-Cola - When 'out and about' >= 5 and Awareness is any of Coca-Co...
28. Press Create filter.
29. OPTIONAL: You can view and edit the conditions by selecting the variable in the Data Sets tree and clicking FILTER DEFINITION > Modify... in the object inspector.
Using Is Within Last Period and Is Within Last to Filter Cases
In the previous example, we used the is after function to filter cases based on whether the Interview date was greater than 01/01/2012. If you would rather filter cases based on how long ago the interviews took place, instead of having to hard-code the starting point, the following functions are designed for that purpose.
- is within last period allows you to create a filter that focuses on how long ago the interview was conducted, for example within the last 2 years or months.
- is within last lets you create a filter that focuses on how much time has elapsed from when the time the interview was conducted and your current time. This function is particularly useful if you want your filter to automatically update each time you run the filter.
There is an important distinction between these functions:
- is within last period is based on values in your data. For example, if your data set contains interviews between 01/01/2015 and 12/31/2019, and you want to filter by interviews conducted in the last year, the filter will use interviews from 2019. In other words, the function uses values in the data.
- is within last uses today's date or time as the starting point. For example, if you want to filter interviews from the last 30 days, if today's date is June 28, 2023, the filter will only use interviews from the end of May, 2023 until June 28, 2023.
For example, to filter cases based on the last 2 years
- Select Any > Filter > New
- Select your filter variable from the Select Data menu
- Select is within last period from the function menu
- Select Year from the time period menu and specify the desired number of years.
The results are as follows:
Note that the information box at the top says dates will be selected within the last 2 years in the data.
To filter cases based on the last month (the elapsed time between when the event occurred and the current date or time)
- Select Any > Filter > New
- Select your filter variable from the Select Data menu
- Select is within last from the function menu
- Select Month from the time period menu and the desired number of months. As of this writing, the current date in July 3, 2023.
The information box at the top lets you know that dates will be selected from the current month. - To check your results, drag your date variable onto the page
- In the Object Inspector, filter the cases by your new filter variable:
The results are as follows. Only the cases in the current month are selected.
Technical details
Filters created with the filtering tool will automatically be structured into a Nominal (categorical) variable. However, the underlying values of the filter are binary (Selected = 1 and Not selected = 0). The Nominal variable will show these categories if used in a table like so:
However if you would like to only show a % of selected without the header, you can change the Structure of the variable to Binary-Multi via the object inspector of the variable. You can click Fix to confirm you want to count Selected and include Not selected in the base:
Then your variable will appear as so in tables:
Next
How to Tag a Variable as a Filter
How to Create a Binary Filter from selected data
How to Create a Text Box Filter
How to Create a Combo Box Filter
How to Create a List Box Filter
How to Connect Filters to Controls using R Code
How to Build Tables that Automatically Filter to the Latest Periods