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
- Combo and list box selections (Advanced only)
In the first 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)
And in the second example, we will use the Advanced option to create a filter with 2 conditions:
- Include gender based on combo box selection AND
- Exclude 18-24 year olds
Requirements
- A Displayr document containing a data set.
- A set of variables to be included in a filter.
Method
Using Is Within Last Period and Is Within Last to Filter Cases
Basic Filter Conditions
The first example uses the default Basic toggle selection at the top right corner.
1. Hover over a variable in the Data Sources tree, and click + > 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 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 Sources tree and in Properties , clicking Filter.
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
- In the Data Sources tree, click + > 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. - Press Create filter.
To filter cases based on the last month (the elapsed time between when the event occurred and the current date or time)
- In the Data Sources tree, click + > 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 is July 3, 2023.
The information box at the top lets you know that dates will be selected from the current month. - Press Create filter.
- To check your results, drag your date variable onto the page
- In Properties
> Filters & Weight > Filter(s), filter the cases by your new filter variable:
The results are as follows. Only the cases in the current month are selected.
Advanced Filter Conditions
This example uses the Advanced toggle selection to enable the inclusion of combo and list boxes in the filtering conditions. Importantly, using this option requires you to use Advanced logic functionality for all conditions in your filter variable. If you later select Basic, it will notify you that any control conditions will then be lost.
- In the Data Sources tree, click + > Filter > New.
-
Select Advanced in the toggle at the top right corner.
- Select the Gender variable from the Select Data menu.
- Change selection below to selections in control.
-
Select the combo box with the matching categories.
Note, for this logic to work, it expects that the category labels in the selected variable will match the item list categories in the selected control.
- Click Add Condition.
- Select the Age variable from the Select Data menu.
- Change any of to none of.
-
Tick the checkbox for 18 to 24.
- Press Create filter.
Technical details
To update any filter conditions, select your variable in the Data Sources tree and click Attributes> Filter via Properties of the variable.
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 Properties 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:
For troubleshooting filter variables, see How to Investigate Filters that Show Incorrect or Odd Results.
Next
How to Create Filters Using Variables in Your Data
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