0
0
Power-biHow-ToBeginner · 4 min read

How to Create Relationships in Power BI: Step-by-Step Guide

In Power BI, you create a relationship by going to the Model view, then dragging a field from one table to a matching field in another table. This links the tables so you can analyze data across them seamlessly.
📐

Syntax

Creating relationships in Power BI is done visually, not by code. The key parts are:

  • Model view: The area where you manage table relationships.
  • Primary key: The unique field in one table.
  • Foreign key: The matching field in another table.
  • Cardinality: Defines the relationship type (one-to-many, many-to-one, etc.).
  • Cross filter direction: Controls how filters flow between tables.
power_bi
1. Open Power BI Desktop.
2. Click on the Model icon on the left sidebar.
3. Find the tables you want to connect.
4. Drag the key field from one table to the matching field in the other.
5. Adjust relationship settings if needed (cardinality, cross filter direction).
6. Click OK to create the relationship.
💻

Example

This example shows how to create a relationship between a Sales table and a Products table using the ProductID field.

After creating this relationship, you can build reports that combine sales data with product details.

power_bi
1. In Power BI Desktop, go to Model view.
2. Locate the Sales table and the Products table.
3. Drag the ProductID field from Products to ProductID in Sales.
4. Power BI automatically sets the relationship as one-to-many (one product to many sales).
5. Confirm and save the relationship.
Output
A line appears connecting the two tables on ProductID, indicating the relationship is active.
⚠️

Common Pitfalls

Here are common mistakes when creating relationships in Power BI:

  • Fields don’t match: Trying to connect fields with different data types or no common values.
  • Multiple relationships: Creating more than one active relationship between the same tables can cause confusion.
  • Incorrect cardinality: Setting one-to-one when it should be one-to-many or vice versa.
  • Cross filter direction: Wrong direction can block expected filtering in reports.

Always check data types and uniqueness before creating relationships.

power_bi
/* Wrong way: Connecting fields with different data types */
// ProductID in Products is text, ProductID in Sales is number
// This will not create a valid relationship

/* Right way: Ensure both fields have the same data type */
// Convert ProductID in Sales to text or Products to number before linking
📊

Quick Reference

StepActionNotes
1Open Model viewClick the Model icon on the left sidebar
2Identify tablesFind tables you want to relate
3Drag fieldDrag key field from one table to matching field in another
4Set cardinalityChoose one-to-many, many-to-one, or one-to-one
5Set cross filterDecide filter direction (single or both)
6ConfirmClick OK to save the relationship

Key Takeaways

Create relationships in Power BI using the Model view by dragging matching fields between tables.
Ensure the fields have the same data type and compatible values before linking.
Set the correct cardinality and cross filter direction for accurate data filtering.
Avoid multiple active relationships between the same tables to prevent confusion.
Use relationships to combine data from different tables for richer reports.