知識庫

How to display data only when there are N or less data selected in the filter


發佈時間 : 06 Apr 2023
上次修改日期 : 07 Apr 2023

問題

How to display data only when there are N or less data selected in the filter.

<Example>
Suppose you have sales data for each manufacturer.
If 5 or less manufacturers are selected in the filter, the data is displayed.
User-added image
If 6 or more manufacturers are selected, the data is not displayed.
User-added image

環境

  • Tableau Desktop

答案

There are 2 solutions.
Option1 : Using a table calculation filter
Option2 : Using a context filter

<Option 1 -Using a table calculation filter->
1. Connect to Sample Superstore from Tableau Desktop.
2. Drag [Sales] to Columns and [Manufacturer] to Rows.
3. Create a new parameter as following.
User-added image
4. Right click on [Number of possible displaying] -> Show Parameter
5. Create a new calculated field as following.
     Name : Display Restrictions Filter(Option 1)
     Calculation : IF WINDOW_SUM(COUNTD([Manufacturer])) <= [Number of possible displaying]
                              THEN TRUE
                              ELSE FALSE
                              END
6. Drag [Manufacturer] to Filter pane -> Check in 5 or less manufacturers.
User-added image
7. Drag [Display Restrictions Filter(Option 1)] to Filter pane -> Check in "True"
User-added image


<Option 2 -Using a context filter->
1. Connect to Sample Superstore from Tableau Desktop.
2. Drag [Sales] to Columns and [Manufacturer] to Rows.
3. Create a new parameter as following.
User-added image
4. Right click on [Number of possible displaying] -> Show Parameter
5. Create a new calculated field as following.
     Name : Display Restrictions Filter(Option 2)
     Calculation : IF {FIXED:COUNTD([Manufacturer])} <= [Number of possible displaying]
                              THEN TRUE
                              ELSE FALSE
                              END
6. Drag [Manufacturer] to Filter pane -> Check in 5 or less manufacturers.
User-added image
7. Right click on [Manufacturer] -> Add to Context
User-added image
8. Drag [Display Restrictions Filter] to Filter pane -> Click on top right Menu button. -> All Values in Context ->Check in True
User-added image
這篇文章是否解決了問題?