Last Modified Date: 24 Mar 2016
Article Note: This article is no longer actively maintained by Tableau. We continue to make it available because the information is still valuable, but some steps may vary due to product changes.
Beginning with Tableau 6.0, you can use multiple data sources for a single worksheet. One data source is primary; all others are secondary. For the primary resource, Tableau selects the data source of the first field you add to the view. Or, if one of your data sources is a cube, it must serve as the primary data source. The primary data source creates relationships with fields of the same name and data type that it finds in the other data sources.
To create a view from multiple data sources, you complete these tasks:
- Connect to the data sources.
- Create a master data source that combines the data sources.
- Create calculated fields to distinguish and combine sales data.
- Create relationships among the data sources.
- Create the combined view.
The sections in this article step through these tasks using data from two fictional retail stores, each differing from the other in the types of product sold and the reporting data format used. All other data is the same.
Open a new workbook and connect to the Superstore sample.
Select Data > Connect to Data, and connect to the Coffee Chain sample.
In a blank Excel worksheet, create the following list of all dimensions and measures needed in the final view. Type each term on its own row, all in the same column.
Note: If your data requires additional dimensions, you must repeat them for each value. For example, if you also wanted to display the years in the data, the product list would need to be repeated for each year.
In the Excel worksheet, select the list you just created, and then copy it to the Clipboard.
- In Tableau Desktop 7.0 and 8.0, select Data > Paste Data.
- In Tableau Desktop 6.1 and earlier, select Edit > Paste Data.
From the Clipboard data connection, drag Product to the Columns shelf.
Because the Product field is the first to be placed in the view, a blue circle with a check mark identifies the Clipboard data as the primary data source. You can switch to another source by clicking its title bar in the Data window.
In this section, you create a calculated field to represent Superstore sales, one for Coffee sales, and one that provides a way to add these values to a table of combined sales data.
Select Analysis > Create Calculated Field.
In the Calculated Field dialog box, complete the following steps.
- For Name, type Sales Superstore.
- In the Formula box, build the following formula:
replacing DATA-SOURCE-NAME with the name of your Superstore sample. The one used to create this article is called Sample - Superstore Subset (Excel).
- Confirm that the status message indicates that the formula is valid, and then click OK.
Create a second calculated field, naming it Sales Coffee, and using the following formula:
ZN(SUM([Sample - Coffee Chain (Access)].[Sales]))
Replace Sample - Coffee Chain (Access) with the name of your Coffee Chain sample if it differs.
Create a third calculated field, naming it Sales Works, and using the following formula:
IF ISNULL([Sales Coffee]) THEN 0 ELSE [Sales Coffee] END +
IF ISNULL([Sales Superstore]) THEN 0 ELSE [Sales Superstore] END
This formula tells Tableau that if the value is null, put a zero value in the table; otherwise, insert the value itself. You can add as many lines to this calculation as you need for each data source used in the table.
Remember that Tableau designated the Clipboard data as the primary data source, because the first field you placed into the view was from this data source. This section steps through linking Clipboard to the two secondary data sources. It does this through corresponding fields, in a manner similar to the way you set up joins.
- For Tableau Desktop 7.0 and 8.0, select Data > Edit Relationships.
- For Tableau Destkop 6.1 and earlier, in the Data window, right-click Clipboard and select Relationships.
In the Relationships dialog box, complete the following steps to set up the relationship among the data sources.
- In the Secondary data source list, select the coffee chain data source.
- Select Custom, and then click Add.
- In the Add/Edit Field Mapping dialog box, select Product on the left and Product Type on the right, and then click OK.
The Product field from the Clipboard data source is now linked to the Product Type field in the coffee chain data source.
In the Secondary data source list, select the Superstore data source, and repeat the previous steps to map the Clipboard Product field to the Superstore Category field.
- Click OK in the Relationships dialog box.
Select each secondary data source to confirm that, in the Dimensions pane, a link icon appears as a visual indicator next to the linked fields.
In the Coffee Chain data source, the indicator appears next to Product Type.
In the Superstore data source, the indicator appears next to Category.
- For Tableau Desktop 7.0 and 8.0, select Worksheet > New Worksheet.
- For Tableau Desktop 6.1 and earlier, select Edit > New Worksheet.
In the Data window, select the Clipboard data source, and from the Dimensions pane, drag Product to the Rows shelf.
Select the Coffee Chain data source, and from the Dimensions pane, drag Product Type to Detail on the Marks card.
Select the Superstore data source, and from the Dimensions pane, drag Category to Detail.
If an alert appears to indicate that you could use a join here, you can ignore the message for this scenario.
In the Data window, select Clipboard.
In the Measures pane, double-click each of the calculations you created earlier:
Sales Coffee, Sales Superstore, and Sales Works.
The measures are added to the Measure Values shelf and the view.
If the automatic view associates the values with color, you can change the view so that the values appear instead. On the Marks card, drag Measure Values to Label.
- For Tableau Desktop 7.0 and 8.0, select Analysis > Totals > Show Column Grand Totals.
- For Tableau Desktop 6.1 and earlier, select Table > Column Grand Totals.
The table shows sales from the Coffee Chain and Superstore files, as well as their combined total.
Alternate Search Terms:primary, secondary, cube, data source, datasource, blending