Relationships
Tableau allows you to create relationships between data sources. The relationship itself is based on a column, or columns, shared between the two tables you are trying to relate. A relationship must have at least one matching pair of fields in order to be created, meaning they must be of the same data type.
One of the great things about relationships with Tableau is that you do not need to specify the join type for the relationship. Tableau takes care of that query behind the scenes for you amongst other things:
- Aggregation: When using fields from related tables, Tableau will automatically aggregate data based on the relationships created.
- Logical Data Model Creation: Tableau also builds a logical data model when a relationship is made. The model itself is a represenation of each individual field you associated with each other for the relationship.
- Integration: Once the relationship is established, fields from both tables will be available when creating a new worksheet. Tableau will automatically use the relationship to combine and display the data correctly.
Creating a Relationship
In order to create a new relationship, you can simply drag existing data sources onto the canvas and select the appropriate columns to relate.
- In the example below, we initially connected to the
cleaning-data-practice
data source which serves as the root table for building the relationship. After creating an additional connection to thetransaction-data
data source, dragging it onto the canvas alongsidecleaning-data-practice
created a relationship between the two.
- Initially, we received an error message notifying us that matching fields need to be selected in order to create the relationship
- Selecting the
transaction_total
from each table cleared the error message, allowing us to establish the relationship using the matching fields of data.
- As mentioned above, you can add as many fields as you like to the relationship as long as you have fields that allow it.