IN TABLEAU DESKTOP IF I CHOOSE A PARAMETER "1" THEN A DIMENSION WILL BE FILTER BY ONLY CATEGORY "A" AND "B" ELSE THE REST OF CATEGORIES
Assistant
In Tableau Desktop, you can achieve this conditional filtering based on a parameter by following these steps:
Step 1: Create a Parameter
Create a Parameter:
Right-click in the Data pane and select Create Parameter.
Name the parameter (e.g., "Category Selection").
Assistant
It seems you didn’t include any additional details or questions. If you need further assistance or clarification regarding the steps for implementing conditional filtering in Tableau, or if you have any other questions or topics you’d like to explore, feel free to let me know! I'm here to help!
User
NOT IN DOES NOT WORK IN TABLEAU DESKTOP
Assistant
You're correct that the use of NOT IN can lead to unexpected results when used in a calculated field for filtering in Tableau. To implement your requirement of filtering based on a parameter with conditions for specific categories, we can rework the approach. Instead of using , we will use a combination of statements checking the categories directly.
Set Data type to Integer.
Set Allowable values to List, and then add the values 1 and 2.
Click OK.
Step 2: Create a Calculated Field for Filtering
Create a Calculated Field:
Right-click in the Data pane and select Create Calculated Field.
Name the calculated field (e.g., "Category Filter").
Use the following formula:
sql
IF [Category Selection] = 1 THEN
[Category] IN ("A", "B")
ELSE
[Category] NOT IN ("A", "B")
END
This conditional logic will evaluate to TRUE for categories "A" and "B" when the parameter is set to 1, and to categories other than "A" and "B" when the parameter is set to 2.
Step 3: Apply the Calculated Field as a Filter
Add the Calculated Field to the Filters:
Drag the "Category Filter" calculated field to the Filters shelf.
When prompted, choose True to only include the relevant categories based on the parameter value.
Step 4: Show Parameter Control
Show Parameter Control:
Right-click on the "Category Selection" parameter in the Data pane and select Show Parameter Control.
This will add a dropdown or slider to your worksheet, allowing users to choose between 1 and 2.
Step 5: Visualize
Create your Visualization:
Build your visualization as needed. The filter will now adjust based on the parameter selected.
Conclusion
Now you have set up a parameter and a calculated field to filter your dimension based on the parameter value. When you select 1, the visual will show only categories "A" and "B", and when you select 2, it will show the rest of the categories.
Make sure to test the interaction in your workbook to ensure everything works as expected!
NOT IN
IF
Here’s how to set it up:
Step 1: Create a Parameter
Create a Parameter:
Right-click in the Data pane and select Create Parameter.
Name it something like "Category Selection".
Set Data type to Integer.
Set Allowable values to List, then add:
1
2
Click OK.
Step 2: Create a Calculated Field for Filtering
Create a Calculated Field:
Right-click in the Data pane and select Create Calculated Field.
Name it something like "Category Filter".
Use this formula:
sql
IF [Category Selection] = 1 THEN
[Category] = "A" OR [Category] = "B"
ELSE
[Category] != "A" AND [Category] != "B"
END
Step 3: Apply the Calculated Field
Add the Calculated Field to the Filters:
Drag the "Category Filter" calculated field to the Filters shelf.
When prompted to specify which values to filter, select True.
Step 4: Show Parameter Control
Show Parameter Control:
Right-click the parameter you created (e.g., "Category Selection") in the Data pane.
Select Show Parameter Control.
This will make the parameter visible, allowing you to toggle between 1 and 2.
Step 5: Create Your Visualization
Create Your Visualization:
You can now create your visuals, and the filtering will respond to the parameter selection.
Explanation of the Logic
When the parameter is set to 1, the calculated field will check for categories A and B, returning True for those categories.
When set to 2, it checks that the category is not A and not B, returning True for all other categories.
This approach avoids the complexity of NOT IN and should give you the desired functionality in your Tableau dashboard. If you have further questions or need assistance with anything else, feel free to ask!