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
Please note these steps require a Displayr license.
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 Report tree and note the Structure in General > GENERAL > Structure in the object inspector on the right.
- Click on the Values button in the object inspector 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 combination of filters is wrong, 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 if you indeed want the missing data to be 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 Report tree, and you will see if that filter was created using our filtering tool, JavaScript code, or R code. There are sections on each type below.
In the filtering tool
In the object inspector click on FILTER DEFINITION > Edit 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 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 0
See How to Work with Conditional JavaScript Formulas and JavaScript Fundamentals for more information on how to write JavaScript code.
In an R filter variable
R filter variables are most commonly used when filtering using interactive controls such as combo boxes, but you can 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 close 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 in a table.
- If you created controls automatically using one of Displayr's automations, the item list of the options for the control were hardcoded and trimmed of whitespace. Thus, if you relabel a category in your variable, you must also amend the Items list field in your control.
- 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
Contact 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.