Tableau 简明教程

Tableau - Context Filters

Tableau 中的普通筛选器彼此独立。这意味着每个筛选器都会读取源数据中的所有行,并创建其自己的结果。但是,在某些情况下,您可能希望第二个筛选器仅处理第一个筛选器返回的记录。在这种情况下,第二个筛选器称为从属筛选器,因为它们仅处理通过上下文筛选器的数据。上下文筛选器有两种主要用途。

The normal filters in Tableau are independent of each other. It means each of the filter reads all the rows from the source data and creates its own result. However, there may be scenarios where you might want the second filter to process only the records returned by the first filter. In such a case, the second filter is known as dependent filters because they process only the data that passes through the context filter. Context Filters serve two main purposes.

  1. Improves performance − If you set a lot of filters or have a large data source, the queries can be slow. You can set one or more context filters to improve the performance.

  2. Creates a dependent numerical or top N filter − You can set a context filter to include only the data of interest, and then set a numerical or a top N filter.

Creating Context Filter

使用示例超级商店,找出称为家具的类别的产品前 10 个子类。为实现此目标,请执行以下步骤。

Using the Sample-superstore, find the top 10 Sub-Category of products for the category called Furniture. To achieve this objective, following are the steps.

Step 1 - 将维度子类拖到行功能区,将度量销售额拖到列功能区。选择水平条形图作为图表类型。将维度子类再次拖到筛选器功能区。您将获得以下图表。

Step 1 − Drag the dimension Sub-Category to the Rows shelf and the measure Sales to the Columns Shelf. Choose the horizontal bar chart as the chart type. Drag the dimension Sub-Category again to the Filters shelf. You will get the following chart.

context filter 1

Step 2 - 右键单击筛选器功能区中的字段子类,然后转到名为顶部选项的第四个选项卡。按字段选择选项。从下一个下拉列表中,选择按销售金额前 10 名,如下图所示。

Step 2 − Right-click on the field Sub-Category in the filter shelf and go the fourth tab named Top. Choose the option by field. From the next drop-down, choose the option Top 10 by Sales Sum as shown in the following screenshot.

context filter 2

Step 3 - 将维度类别拖到筛选器功能区。右键单击进行编辑并在常规选项卡下从列表中选择家具。正如您所见的,结果显示了三个产品子类别。

Step 3 − Drag the dimension Category to the filter shelf. Right-click to edit and under the general tab choose Furniture from the list. As you can see the result shows three subcategory of products.

context filter 3

Step 4 - 右键单击类别:家具筛选器,然后选择添加到上下文选项。这就生成了最终结果,显示了家具类别中排在前 10 个子类别中的产品子类别。

Step 4 − Right-click the Category: Furniture filter and select the option Add to Context. This produces the final result, which shows the subcategory of products from the category Furniture which are among the top 10 subcategories across all the products.

context filter 4