Use this article when you apply a filter(s) to a table and get a result you don't expect. At a high level, you need to:
Confirm the issue is with the filter and not the variable sets
Confirm categories and values of the filter are correct
Confirm the issue is with the filter and not the other variable sets
- Create a new table of the underlying data that looks wrong without any filters, weights, or rules applied.
- Confirm that the Count and Sample Size values match what you expect.
- Duplicate the table and add the filters you're using one by one.
- The filter added directly before the table starts looking wrong is likely the filter with an issue.
- Remove all filters except for the filter from the previous step to confirm whether that individual filter is wrong or if a combination of that filter and others is wrong.
- Depending on the filter's complexity, create crosstabs or nested banners of variables used in the filter to confirm that the counts you expect for the various criteria are indeed the counts in the data.
Confirm categories and values of the filter are correct
- Click on the filter variable in the Data Sources tree and note the Structure in Data > Attributes in the Properties
.
- Click on the Values & Labels, Values, or Categories button, depending on the variable's structure in the Properties to confirm the values and categories are correct for the filter's goals:
-
Nominal variables: all categories that have a Value greater than zero are included in the filter, no matter what the Missing Values setting may be. For example, the setup below will filter out Male responses and include Female responses if this variable is used as a filter.
-
Binary variables: only the values checked for Count this Value will be included in the filter. The example below will filter out Male responses and include Female responses:
-
Nominal variables: all categories that have a Value greater than zero are included in the filter, no matter what the Missing Values setting may be. For example, the setup below will filter out Male responses and include Female responses if this variable is used as a filter.
- If you want to create filters for each category in a Nominal variable (based on how the categories are configured in its summary table), see How to Create a Binary Filter from Selected Data.
Check for missing data
- Drag each incorrect filter(s) variable to the page to create a table where you can view the counts for 0/Not selected (filtered out) responses and 1/Selected (included in the filter) responses. If a filter combination is incorrect, you can also review the counts in a crosstab of both filters.
- If the NET of the filter is less than the Total Sample size of your data, some cases have missing data for the filter and are inherently being filtered out. This is likely due to missing data in one of the variables used in the filter. Confirm whether you want the missing data filtered out. If not, you need to edit the filter's criteria or code of your variable to account for missing data.
- If the NET of the filter is the Total Sample size or the sample size you expect, this means the criteria/code of the filter variable is incorrect.
Review your filter's criteria
Click on your filter variable in the Data Sources tree, and you will see if that filter was created using our filtering tool, JavaScript code, or R code. Sections on each type are below.
In the filtering tool
In Properties click on Data > Filter to open the filtering tool and review the logic. See How to Create a Complicated Filter for how to use the tool. The criteria is set up in a hierarchy, and you can nest groups of logic (in yellow below) inside the entire list of criteria (in pink below). The way to read the criteria below is "respondents whose Gender is Male AND Income is 90k or more AND (are Aware of Diet Pepsi or Prefer Diet Pepsi)". Each criterion and group of criteria lists the number of respondents selected (in green below), which you can match to summary tables of those questions used to confirm that the correct number of respondents is selected for each criterion. The total number of respondents selected by the filter is at the very bottom of the window.
If individual criteria are selecting the expected number of cases, then the groupings or logic (ALL, ANY, etc) should be reviewed. If a variable used in ALL logic has missing data, it's likely that the missing data is not selected, which will exclude those respondents from the filter, even if other criteria in the ALL group are met. Confirm this is how you want the logic to work.
In an Advanced control filter variable
Current Combo Box and List Box controls, which are used for interactive filtering, are created as Advanced logic filter variables which you can manually append conditions to. This option is available when Advanced is selected in the toggle at the top right corner.
If this filter variable isn't flagging the correct respondents, in addition to the above steps, the following should be checked.
- The filter works by matching category labels exactly between the referenced variable set and the selected control. If the labels don't match, this will prevent the filter from working correctly. Importantly, this method uses the Label of categories from Nominal variables rather than the underlying Value. It also takes into account if a category has been renamed, combined or removed in a table.
- If you created controls automatically using one of Displayr's automations, the item list of the options for the control would be hardcoded and trimmed of whitespace. This means if you relabel a category in your variable or a table of your variable, you must also amend the Item list field in your control. Also, if you have leading or trailing spaces in your variable category label, these will need to be removed in order to match exactly with the Item list.
- Check that the combo box reference in the relevant conditions points to the correct control in relation to the selected variable set to match against.
- If the control no longer exists, the filter variable will error accordingly on variable hover, in the object inspector, and within the appropriate filter logic condition. Changing the name of a control referenced in a filter variable will automatically update, so this issue will only occur if the control itself has been deleted.
See also How to Create a Combo Box Filter and How to Create a Complicated Filter.
In an R filter variable
The current filters for Date and Text Box controls, as well as older Combo Box and List Box controls, are created using R filter variables, but you can also create your own filter logic manually. If your R Code isn't flagging the correct respondents, drag the variable onto the page to create a table showing the Count that you can check as you troubleshoot the code. It's likely your R filter will be set up using conditional formulas and may also include if-else logic. See How to Work with Conditional R Formulas for instructions on how to create criteria and logic for your R variable. Some quick things to check with troubleshooting filter code:
- Place your cursor next to a parenthesis () in the R Code to highlight both the open and closed pair in grey to confirm your logic is grouped correctly.
- Hover over variables highlighted in the code to confirm what the data looks like that R is using in the preview. For example, R uses the Label of categories from Nominal variables rather than the underlying Value. R also takes into account if a category has been renamed, combined or removed in a table.
- If you created controls automatically using one of Displayr's automations, the item list of the options for the control would be hardcoded and trimmed of whitespace. This means if you relabel a category in your variable or a table of your variable, you must also amend the Item list field in your control. Also, if you have leading or trailing spaces in your variable category label, these will need to be removed in order to match exactly with the Item list.
- If referencing a control, use the arrow in the preview to jump to it and confirm it is indeed the control you should be referencing for your filter.
- Are you using the appropriate "if" in your code? Use an if(){}else{} structure for checking a single value against others vs using the ifelse() function, which will return a vector of true/false, see Challenges With 'if' When Writing R Code for more detail.
See How to Troubleshoot R Code in Displayr for more involved troubleshooting steps or one of the following articles - if applicable, to confirm that the variable is created as expected:
- How to Connect Filters to Controls Using R Code
- How to Combine Multiple R Filter Control Variables into a Single Variable
- How to Add a Total Sample Category to a Single Selection Control
- How to Create a Combo Box (Drop-Down Control) With a Dynamic List
In a JavaScript variable
If your JavaScript Code isn't flagging the correct respondents, drag the variable onto the page to create a table showing the Count that you can check while you troubleshoot the code. Keep in mind: JavaScript uses variable names, the code is case-sensitive, and the underlying Value of the variables should be used in logic unless you've used the Q.Label function. For example, a filter that selects Male responses (which has a value of 1) for the Gender variable (d3) you could use:
if(d3 == 1) 1
else 0
if(Q.Label(d3) == "Male") 1
else 0Contact support if needed
If you've worked through these steps and haven't found a cause or solution to the issue, please contact our support team at support@displayr.com or by clicking on Help > Contact support from within your specific document in Displayr. Please provide the details of what you learned from above and why you think the filter isn't working as expected.