Tableau 简明教程
Tableau - Data Blending
数据混合是 Tableau 中一个非常强大的功能。当多个数据源中存在相关数据时,您希望将它们分析到单个视图中,这时就使用数据混合。例如,考虑了在关系数据库中的销售数据和 Excel 电子表格中的销售目标数据。现在,为了将实际销售额与目标销售额进行比较,您可以基于公共维度混合数据以获取 Sales Target 度量。数据混合中的两个源被称为主要数据源和辅助数据源。在主要数据源和辅助数据源之间创建左连接,其中包括主要数据源的所有数据行以及来自辅助数据源的匹配数据行。
Data Blending is a very powerful feature in Tableau. It is used when there is related data in multiple data sources, which you want to analyze together in a single view. As an example, consider the Sales data is present in a relational database and Sales Target data in an Excel spreadsheet. Now, to compare actual sales to target sales, you can blend the data based on common dimensions to get access to the Sales Target measure. The two sources involved in data blending are referred as primary and secondary data sources. A left join is created between the primary data source and the secondary data source with all the data rows from primary and matching data rows from secondary data source.
Preparing Data for Blending
Tableau 有两个内置数据源 Sample-superstore 和 Sample coffee chain.mdb ,它们将用于说明数据混合。
Tableau has two inbuilt data sources named Sample-superstore and Sample coffee chain.mdb which will be used to illustrate data blending.
首先,将示例咖啡连锁店加载到 Tableau 并查看其元数据。转到菜单 - Data → New Data Source 并浏览示例咖啡连锁店文件,它是一个 MS Access 数据库文件。下面的屏幕截图显示了文件中提供的不同表和连接。
First load the sample coffee chain to Tableau and look at its metadata. Go to the menu - Data → New Data Source and browse for the sample coffee chain file, which is a MS Access database file. The following screenshot shows the different tables and joins available in the file.
Adding Secondary Data Source
接下来,通过再次按照步骤 - Data → New Data Source 并选择此数据源来添加名为 Sample-superstore 的辅助数据源。这两个数据源现在会像下面的屏幕截图中所示那样显示在 Data 窗口中。
Next, add the secondary data source named Sample-superstore by again following the steps - Data → New Data Source and choosing this data source. Both the data sources now appear on the Data window as shown in the following screenshot.
Blending the Data
现在,您可以基于公共维度集成来自以上两个源的数据。请注意,在名为 State 的维度旁边会出现一个小的链条图像。这表示两个数据源之间的公共维度。将主数据源中的 State 字段拖动到 rows 货架,将次数据源中的 Profit Ratio 字段拖动到 Columns 货架。然后,从 Show Me 中选择子弹图选项以获取下面的屏幕截图中所示的子弹图。该图表显示了连锁超市和咖啡店中各个州的利润率如何变化。
Now you can integrate the data from both the above sources based on a common dimension. Note that a small chain image appears next to the dimension named State. This indicates the common dimension between the two data sources. Drag the State field from the primary data source to the rows shelf and the field Profit Ratio from the secondary data source to the Columns shelf. Then, select the bullet chart option from Show Me to get the bullet chart shown in the following screenshot. The chart shows how the profit ratio varies for each state in both the superstore and coffee chain shops.