Updated July 28, 2023
Introduction to Tableau Joins
A way to extract data from multiple tables in the database is by Tableau Joins. They enable us to get data from different tables provided that the tables have certain fields common. The common field shall be the primary key in one table that acts as a foreign key in another. Various types of Joins include Inner Join, Left Join, Right Join, and Full Outer Join. Tableau allows us to perform joins in a very easy manner. It offers a guided approach to join the two tables providing a couple of important options. Using the functionality we can get data from different tables for analysis.
Types of Joins in Tableau and their Application
First, we will load the data source into Tableau. For this demonstration, we are using Employee data in Excel file. There are two tables present on two different sheets. The first table is Employees and the second table is Salaries. The Employees table contains dimensions Employee ID, Birth Date, First Name, Last Name, Gender, and Hire Date. The Salary table contains dimensions of Employee ID, Salary, and From Date. Employee ID is present in both the tables. Also, Hire Date and From Date is the same fields but with different names.
- In the Data menu click on the “New Data Source” option. Then select the data source type.
- In our case, it is present as a Microsoft Excel file. Load the data source. The following screenshot illustrates this.
- The data source gets loaded as below. Now, we will drag the tables “Employees” and “Salaries” one-by-one into the “Drag sheets here” section.
- First, we dragged the Employees table as below.
- Now, see what happened when we dragged Salaries table also, an inner join got created automatically. The intersecting circles represent a join.
1. Inner Join
- Hovering mouse over the intersecting circles gives details about the join as can be seen in the below screenshot.
- Click on the intersecting circles, and a box will pop-up. As can be seen, there are four types of joins viz. Inner, Left, Right and Full Outer. Currently, Inner join is selected which returns only common data between two tables. It’s like the intersection of two sets.
2. Left Join
When the Left join is applied over two tables, complete data from the left table is considered, and only that data from the right table is considered which is common between the two. The following screenshot shows this.
- As can be seen in the above screenshot, in the right corner of the screenshot, there are “null” entries for dimensions from the Salaries table. This is because we have applied Left join and Employees table is the left table.
3. Right Join
When Right join is applied over two tables, complete data from the Right table is considered, and only that data from the left table is considered which is common between the two. The following screenshot illustrates this.
- As can be seen in the above screenshot, in the left corner of the screenshot, there are “null” entries for dimensions from the Employees table. This is because we have applied Right join and Salaries is the right table.
4. Full Outer Join
When applied, the join returns the data that is common to both the tables, along with the data from both the tables that is uncommon between the two. The following screenshot demonstrates this.
- Using the drop-down menu as shown in the below table, we can select the common field for joining the two tables. Selecting the wrong fields will not join the tables giving the wrong result.
- Now, we will check if the data returned by the join correctly works, when we try to analyze it on the sheet. In the Data section, we can see the two tables and their respective dimensions. Drag dimensions First Name and Employee ID into Rows region and Salary measure into Columns region. Click on the “text tables” option in “Show Me”, data gets presented in the following form. As we can see, for certain Employee IDs and First Names, no value has been returned for the Salary measure. This is because, when we select Employee ID from the Employees table, all Employee IDs in that table will be returned and also the corresponding First Names, but those entries are not present in the Salaries table, as a result, no value in Salary column is returned for those entries.
- Now, we remove the Employee ID from the Employees table and drag Employee ID from Salaries table into Rows region. We get the result as in the below screenshot. As can be seen, this time all Employee IDs from Salaries table has been returned, along with corresponding First Names and Salaries. This time, for certain entries in the First Name column, Employee ID and Salary have returned no value. This is because those entries in the First Name are present in the Employees table but not in the Salaries table.
- In both the above cases, we got a result from both the tables. The common entries were returned along with details from both the table. However, we must keep in mind that the primary key must be selected from the appropriate table, as shown by the above examples. This is crucial when we have to generate insights on data extracted from multiple tables.
- Now, we will explore in brief the options in the drop-down menu of the table below. Click on the drop-down menu of table Employee, and certain options will appear. The first option that is selected automatically is “Field names are in the first row”. This option displays the names of the fields as headings in the first row. “Generate field names automatically” generates field names automatically. “Convert to Union” option will create a union between the two tables. The “Duplicate” option creates a copy of the table as if we click on Duplicate for Employees, it will create a copy, Employees1. Clicking on the “Remove” option will remove that table from the pane.
Join is a crucial concept in data warehousing that allows us to bring data from multiple tables together. They work like set operations in mathematics. Tableau offers an easy-to-implement approach, to implement joins between multiple tables, which facilitates detailed analysis as we can have the required data at our disposal.
This is a guide to Tableau Joins. Here we discussed the introduction and types of Joins in Tableau and their application. You can also go through our given articles to learn more-