Union Related Data Across Multiple Excel Tabs

RELATED ARTICLES

Product(s):  Tableau Server, Professional Edition
Version(s):  6.1
Last Modified Date:  10 Dec 2011
You may have a workbook that has data spread across multiple tabs. For example, a workbook containing information about several different regions with each region on a separate sheet. While you may be tempted to join these tabs together, what you actually need to create is a union.


A join makes the table wider (i.e., adds more columns) while a union makes the table longer (i.e., adds more rows). As long as the columns are the same across all the tabs, you can create a very simple union so you can compare the regions to each other.

Reformatting the data.

Below is a workbook that has two tabs that contain regional sales data. Each tab represents a different region.

You could combine these all into a single sheet by copy and pasting in Excel. In this case, you will have to maintain that second sheet as data changes over time. Another option is to create a union between the sheets.

Note: Future sheets will require you modify the data connection.

In the Connect to Data dialog box, browse to the Excel workbook of interest. Then select the Custom SQL option.

union_similar_data_excel_3.png

By default the SQL query for the a single sheet will display. Replace that query with something like what is shown below:

Replace the bracketed content above with the names of your sheets. The dollar sign must be added to the sheet names in the above formula when working with Excel.

Connection dialog showing the Custom SQL for a union query.

Note: If your sheet names have spaces in them make sure to include single quotes around the sheet name. For example if your sheet name was "Eastern Region" you would type ['Eastern Region$'] as part of the query.

When finished, click OK. You can see that you now just have a single table containing all of the fields. When you drag Region to the view, you will see that you have data for both the East and West.

Advanced Tip

The Excel workbook used in the example has a column on each sheet for Region. If you don't have that column you should modify the union statement to something like the one shown below:

This query creates a new column for Region using the data from the East and West tabs.

Caution: The union has to be processed every time Tableau queries the data source (e.g., you drag fields around the view, filter, etc.). This could take a long time depending on the size of your Excel file. You can create an Extract by selecting Data > Extract to avoid these issues.

Alternate Search Terms: How To Data Sources
Need more help? Contact Support


ATTACHMENTS





Search Knowledge Base