Relationships in Tableau
Overview
Time: minObjectives
How to build relationships in tableau
- Tableau allows combining more than one table from the dataset. There are two ways in which we can accomplish this –joining the tables or establishing relationship between the tables.Establishing a relationship is more flexible as compared to joins is because you do notneed the specify the join type. Tableau creates a relationship based on matching column names or existing key constraints. It adjusts the join and preserves the LOD (level of detail) of the data. Relationships are dynamic, tables are not merged at data source level but are joined automatically, based on fields in use. The difference between joins and relationship is that –when you create a relationship, the tables are combined at the logical layer whereas when you create a join tables are combined at the physical level. Hence relationships are flexible,and joins are static.
- Let us start building relationships.Start by importing data in Tableau. The Data Source page will have all the tables from the uploaded dataset.
- Now drag the first table that you require on the canvasand you will see all the rows and columns populated.Drag the second table and you can see a connection between the two tables. You have now established a relationship between two tables.
- The relationship is created by connecting common columns from both the tables. You can add more fields/columns you want to connect.The performance options include selecting cardinalityand referential integrity. If you are unsure about any of the parameters,you can stick to the defaults.
- You can establish relation between multiple tables.
-
Suppose you have two tables, employee table with employee_id as the primary key, employee_names, employee_address and employee_hiredate and department table with department_id, department_name and worker_id.Now in these two tables, employee_id and worker_id columns are the same, but they have different column name. In that case, you will have to choose the columns you want to join on. That is,you will have to select employee_id and worker_id to establish the connection.
-
Now, let us say you want to create a join rather than a relationship. In that case double click on the orders table. This will give you access to the physical layer. Now drag the table you want to join.
- To change the type of join, click on the join icon (venn diagram) and you will have all the join options.
- Let us look at all the measures and dimensions populated after we have established the relationship.We can see that the measures and dimensions have been split up table-wise.
- Whereas if we perform join, we can see all the dimensions from both the tables and all the dimensions from both the tables.
Key Points