When you create a Combo Box Filter (or List Box filter) from a variable that has Missing Data, you may want to customize how the filtering handles the missing data. You can determine when and how to show Total Sample when all categories are selected with the methods below.
This article covers:
How Missing Data is handled automatically
Renaming Missing data in the Combo Box Item list
Show Total Sample without Missing data in the Combo Box
Requirements
- A Data set. All the examples in this article were created using a Cola brand tracking (12-month) dataset from Add Data > Sample Data
- Objects on the page to filter (e.g., table, chart, visualization, etc.).
How Missing Data is handled automatically
When you create a Combo Box Filter using the Method - Automatic approach, Displayr automatically adds a Missing Data item to the Item list if variable is a Nominal (categorical) variable and contains missing values.
This is done deliberately. The filter works by matching respondents against whatever is selected in the Item list. If Missing Data was left out of the list, selecting every visible item would only return respondents who fall into one of the named categories - anyone with a missing value would be silently dropped, so (Select all) would no longer be equivalent to the total sample.
For example, the Income variable Sample Size is 707, the Total Sample size is 800, and 93 respondents didn't answer the question and are set as Missing Data (Exclude from analyses in Labels and Values).
Displayr automatically includes Missing data in the Combo Box Item list to ensure the filter returns the total sample of 800 respondents when (Select All) is selected.
If the Missing data is removed from the Item list, the filter returns 707 respondents (Total Sample 800 - Missing Count 93) when (Select All) is selected because Missing data is "not selected" for the filter.
If you create a Combo Box automatically using a Binary-Multi variable set with missing data, missing data is not automatically included when all categories are selected, but you can include it, see Show Total sample without Missing data in the Combo Box.
Renaming Missing data in the Combo Box Item list
One way to include Missing Data in the Combo Box filter is to include Missing Data in question itself. This approach allows us to use a different label for missing data. Using the Income variable as an example.
Step 1 - Rename and include Missing data in the Value Attributes
- Select the Income variable from Data Sources tree.
- Optional: Right-click > Duplicate to create a copy that includes missing data if you don't want to edit the original.
- With the (duplicate) variable selected, click the Values and Labels
icon from the floating toolbar to open the Value Attributes.
- For the row with the Missing data Label, change the Label to what you wish to appear in the Item list (and in any tables and analyses where the variable set is used) and for Missing Values choose Include in analyses. Below is a picture of the edit.
- Select OK.
Step 2 - Revise or Remake the Combo Box Filter
You need to make sure that the Combo Box control and filter variable are configured to account for the renaming. You can either:
- Recreate the Combo Box Filter using Method - Automatic on the modified variable. This is the quickest option if you aren't already using the Combo Box Filter on lots of outputs. You'll want to delete and remove the old Combo Box and filter from the output afterwards.
- Revise the current Combo Box Filter. If your Combo Box Filter is used on lots of outputs throughout your document, you may want to just update its configuration so you don't have to remove and add a the new filter to all those outputs.
To revise the current Combo Box and filter variable.
- Update the Combo Box control to match the new variable. Select the Combo Box control.
- Go to Properties > Control tab.
- Remove Missing data from the Item list since there is no longer missing data in the modified variable.
- In the Combo Box control, check Select all to include all respondents.
- If you modified your original variable, you are finished! Otherwise, continue through the remaining steps.
- In Items from dropdown, choose the duplicated variable you modified (i.e. Income 2).
- Ensure the filter variable is using the modified variable. Select the Combo Box filter variable from the Data Sources menu (i.e. Combo Box Filter Income).
- Go to Properties > Data > Attributes and click Filter Definition.
- Choose the modified variable (i.e. Income 2) from the drop-down list, replacing the original variable, and confirm the 'Selected' returns the total sample.
Note: for the Selected to return total sample size, (Select all) must be selected in the linked Combo Box (see step 4 above). - Select OK.
Show Total sample without Missing data in the Combo Box
It's common to not want Missing Data shown in the Item list shown to viewers - it's rarely a category anyone wants to consciously filter by. However, when viewers choose (Select all) from the Combo Box, they expect and assume the filter returns the Total sample. To implement this, you will need to recreate your filter variable with modified logic using R code. The steps and code depends on the Properties > Control > Selection mode.
- If the Selection mode is set to Single selection (allowing the user to filter by a single category at a time), use the approach described here: How to Add a Total Sample Category to a Single Selection Control.
- If the Selection Mode is set to Multiple selection use the steps and R code below.
For this example we are using the Income Combo Box filter created above.
- If the combo box uses a Nominal variable, you'll need to remove the Missing data category from the Combo Box. Otherwise jump to step 4.
- Select the Combo Box, go to Properties > Control.
- Delete Missing data from the Item list.
- Create a new R filter variable. Hover over a variable in the Data Set you are using in the Data Sources tree, and select + > Custom Code > R > Nominal.
-
Paste the code below into the Code. If the variable used in the Combo Box has a Structure of Binary-Multi, use the code in the Technical notes below.
### This code always include missing data in the filter when all categories are # selected in a combo box/list box control - without having a missing data category ##INPUTS #specify item names, replace the names below with your own theComboBox = ComboBoxIncome #ComboBoxIncome is the Name of the Combo Box on the page theVariable = d2 #d2 is the Income variable's Name - must be Nominal or Ordinal theOrigFilter = combobox_filter_income #combobox_filter_income is the original combo box filter variable ##FILTERING LOGIC #if the number of selections in the combo box is the number of non-missing categories in the variable if (length(theComboBox) == length(levels(theVariable))) { #include all respondents rep(TRUE, length(theVariable)) } else { #otherwise, only include selected categories theOrigFilter } - Read through the comments that explain the code and replace the Names referenced with the Name of each corresponding item in your document. These can be found under Properties
> General > General > Name.
- In Properties, check Usable as a filter.
- On the General tab, give the new filter variable a descriptive Label and Name.
- Select the outputs you want to filter (you can select them all at once if desired), in the Properties > Filters & Weight > Filter(s) uncheck the original Combo Box Filter and check the new R combo box filter to now use the new filtering variable.
Technical notes
Use the following code to show Total Sample when all categories are selected when filtering with a Binary-Multi variable set (e.g. Awareness).
### This code always include missing data in the filter when all categories are
# selected in a combo box/list box control - without having a missing data category
# using a Binary-Multi variable set as the categories
## INPUTS
#specify items, replace the names below with your own
theComboBox = ComboBoxAwareness #ComboBoxAwarness is the Name of the Combo Box on the page
theVariable = `Awareness` #Put the Binary-Multi variable set Label in backticks
theOrigFilter = combobox_filter_awareness #combobox_filter_awareness is the original combo box filter variable
#remove the NET column
theVariable = theVariable[,!colnames(theVariable) == "NET"]
## LOGIC
#if the number of selections in the combo box is the number of categories in the variable
if (length(theComboBox ) == NCOL(theVariable)) {
#include all respondents
rep(TRUE, NROW(theVariable))
} else {
#otherwise, only include selected categories
theOrigFilter
}Next
How to Create a Combo Box Filter
How to Connect Filters to Controls Using R Code
How to Add a Total Sample Category to a Single Selection Control
How to Investigate Filters that Show Incorrect or Odd Results
UPCOMING WEBINAR: From Thousands of Tables To One Clear Story: using AI in survey analysis