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 questions
Confirm categories and values of the filter are correct
Confirm the issue is with the filter and not the questions
- Create a new table of the underlying data that looks wrong without any filters, weights, or rules applied.
- Confirm that the n and appropriate Base n 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
- On the Variables and Questions tab, check that the Question Type is correct.
- Click on the Values ... button to confirm the values and categories are correct for the filter's goals:
- Pick One 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.
- Pick Any (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:
- Pick One 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 Pick One variable (based on how the categories are configured in its summary table), see How to Create Filters from Selected Data.
Check for missing data
- Create a SUMMARY table for each incorrect filter(s) variable where you can view the n 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 n 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 n or the sample size you expect, this means the criteria/code of the filter variable is incorrect.
Review your filter's criteria
On the Variables and Questions tab, right click on your filter variable 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
Right click on the variable and select Edit Filter to open the filtering tool and review the logic, see How to Create and Use Filters 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, create a table showing the n 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, create a table showing the n 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.
- 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 on our sister software Displayr's help center for more detail.
See How to Troubleshoot R Code for more involved troubleshooting steps
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@q-researchsoftware.com or by clicking on File > Share > Send to Q Support (Encrypted) from within your specific project. Please provide the details of what you learned from above and why you think the filter isn't working as expected.