DEV Community

Cover image for Understanding Data Modeling in Power BI: Joins, Relationships and Schemas Explained
Stacy Shimaka
Stacy Shimaka

Posted on

Understanding Data Modeling in Power BI: Joins, Relationships and Schemas Explained

INTRODUCTION
I'm currently learning Power BI and I keep hearing about data modeling. Honestly it sounded very complicated but when i researched and practiced, I realized it's just about organizing data in an organized manner.
In this article I'll explain data modeling in a simple way. I'll cover joins, relationships, schemas and how do do them on power BI step by step.

What is Data Modeling?

Data modeling is simply arranging your data into tables and connecting them so that Power BI can analyze them properly.

SQL Joins Explained

Joins help in combining data from different tables. They include inner join, left join, right join, full outer, left anti and right anti join.
Let's say for example we have this sample data:

Customers Table

ID Name
1 John
2 Alice

Orders Table

Order ID Customer ID
001 1
002 2
003 3

Inner Join
The inner join returns only rows that have matching values in both tables. Therefore using our data, inner join will only show customers who have data that is Customer ID 1&2.

a picture illustrating inner join

Left Join
This returns all rows from the left table (table1), and only the matched rows from the right table (table2).
Good for checking inactive customers.

a picture illustrating left join

Right Join
This returns all rows from the right table (table2), and only the matched rows from the left table (table1).
Helps in finding data errors.

a picture showing right join

Full Outer Join
This returns all rows when there is a match in either the left or right table.
Useful when comparing datasets

a picture showing full outer join

Left Anti Join
This shows customers with no orders.
Helps in businesses when finding inactive users.

Right Anti Join
This shows orders that don't have customers.
Helps clean bad data.

How to Do Joins in Power BI

  1. Open Power BI Desktop
  2. Click Transform Data
  3. Click Merge Queries
  4. Select the your tables[in this case we have two]
  5. Select the matching column[like customer ID]
  6. Choose join type
  7. Click OK
  8. Expand the columns
  9. Click Close & Apply

Relationships in Power BI
Joins and relationships may seem alike but they are not. Relationships connect tables without merging them.

Types of Relationships

  1. One-to-Many One Customer to many orders

one to many relationship illustration

  1. Many-to-Many Many items relate to many others

one to many relationship illustration

  1. One-to-One Used when splitting tables

Cardinality
This just means how tables are connected:

  • One-to-one
  • One-to-many
  • Many-to-many

Cross Filter Direction
This determines which direction filters can flow between tables. A single-direction flow (from dimension to fact table) is preferred to prevent ambiguity and performance issues.

Active vs Inactive Relationships
Active relationships ( appear as solid lines) automatically filter data in visuals, while inactive relationships (appear as dashed lines) exist but are ignored by default. Only one active path can exist between two tables to prevent ambiguity.

active and inactive relationship illustration

How to Create Relationships

  1. Go to Model View
  2. Drag one column to another OR
  3. Go to the Modeling tab and click Manage Relationships
  4. Click New to open the creation dialog box
  5. Select the two tables you want to connect
  6. Click on the column(s) in each table that share data.
  7. Configure the Cardinality (usually One-to-Many 1:) and **Cross- filter direction* (usually Single).
  8. Click OK

Join vs Relationships
Joins combine tables while relationships connect tables.
Joins are done in Power Query while Relationships are done in Model View

Facts and Dimension Tables

Just to put it in a simple way; Fact Tables contain numbers[sales, revenue]while Dimension Tables contain descriptions[customer name, product name].

Schemas

A schema refers to the structure and organization of data within a data model. Schemas define how data is connected and related within the model, influencing the efficiency and performance of data queries and reports. There are two types of schemas: Star schema and Snowflake schema.

Star Schema
It has the fact table at the center connected to the others[Dimension tables]. This is commonly used.

A star schema

Snowflake Schema
The snowflake schema is a normalized version of the star schema but the dimension tables are further divided into related tables, resulting in a more complex structure.

A snowflake schema

Flat Table

A flat table combines all columns into one table. It is commonly used when the dataset is small and is beginner-friendly.

Common Modeling Issues in Power BI

Most Power Bi problems come from a bad data model. Here are some of the common problems:

  1. Flat Tables may result to too much repeated data.
  2. Many-to-Many relationships lead to wrong totals.
  3. Incorrect data types cause failure in calculations.
  4. Wrong relationships lead to inefficiency of the data.

Conclusion

Learning Power Bi may seem a bit confusing or overwhelming . But over time you realize that it's really about one simple idea: Organizing your data in a way that makes analysis easy and accurate. Therefore understanding data modeling in power BI is very essential for building accurate reports.

Top comments (0)