DEV Community

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

Posted on

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

Introduction

In Power Bi, a data model is a collection of tables, relationships, and calculations that represent the underlying structure of your data.
Data Modeling, therefore, is the process of organizing data into tables and defining how these tables relate to each other.
Data modeling happens after loading data and before visualization.

Components of a Power Bi Data Model

1. Tables
These are the basic building blocks of a data model.
2. Columns
These are custom columns that you create in your tables using DAX(Data Analysis Expressions), a powerful formula language in Power Bi.
3. Measures
These are calculations used to aggregate data in a model.
4. Relationships
These determine how tables are connected in a data model.

Why model data?

  • Data is never perfect

  • To reshape data for analysis

  • To compress data usage

  • It is easier to understand a model

Joins in Power Bi

Joins enable you to establish relationships between data tables. A join combines data from two tables into one based on a common column.

Types of joins in Power Bi

1. Inner Join
It returns the rows present in both left and right table only if there is a match.
2. Left Outer Join
It returns all the rows present in the left table and matching rows from the right table.
3. Right Outer Join
It returns all the rows present in the right table and matching rows from the left table.
4. Full Outer Join
It returns all the rows present in both the left and right table

Where to use Joins

Use joins when:

  • You need to clean or transform data

  • You want a single table for simpler analysis

Relationships in Power BI

Relationships in Power BI connect tables allowing data from multiple sources to be analyzed together. They define how rows in one table relate to one another enabling cross-filtering for visuals.
There are several types of relationships:

1. One-to-One Relationship
Each row in the first table is related to only one row in the second table.
2. Many-to-One Relationship
Many rows in the first table are related to one row in the second table.
3. One-to-Many Relationship
One row in the first table is related to one or more rows in the second table.
3. Many-to-Many Relationship
Each row in the first table can be related to multiple rows in the second table

How to create relationships in Power BI

Power BI can auto-detect relationships or allow manual creation for better control.
To create relationships in Power BI, you drag a field from one table onto the corresponding field in another within the Model View.

On the Ribbon click on Manage Relationships:


Power BI Home Tab


Power BI Screenshot To add a relationship

Power BI Screenshot to select tables to add relationships to


Cardinality and Cross-Filtering

Cardinality and Cross-Filtering in Power BI determine how tables relate and how filters pass between them.
Cardinality, e.g., one-to-many, many-to-many, defines the relationship type based on unique key values while Cross-Filtering(single or both) defines the direction filters propagate.

Data Modeling Schemas

What is a schema?

A schema is a blueprint that defines how tables are organized and connected in your model.

Types of schemas

1. Star Schema
The star schema is a simple and commonly used schema in data warehousing. It consists of a central fact table surrounded by dimensions table.

Star Schema
source: _(https://tabulareditor.com/hs-fs/hubfs/Example-of-a-star-schema.jpg?width=754&height=508&name=Example-of-a-star-schema.jpg)

Benefits
  • Has a simpler design
  • It has faster queries
  • It is easier to maintain

2. Snowflake Schema
The snowflake schema is a more normalized version of the star schema. Dimension tables are further divided into sub-tables.

SNowflake schema

source: _(https://share.google/V57rZDUnrxAockCtJ)

Benefits
  • Reduces redundancy

Best Practices for Modeling data in Power BI

To build efficient data models:

  • Use a star schema whenever possible

  • Keep relationships simple and clean

  • Remove unused columns

  • Perform data cleaning before modeling

Example:
Say we are analyzing sales data.

Step 1: Load Data
  • Import the Sales, Customers, and Products tables.
Step 2: Clean Data
  • Use Power Query
  • We are going to remove duplicates, handle missing values and ensure consistent data models.
Step 3: Create relationships
  • For the Sales table and Customers table, choose customerid and id respectively
  • For the Sales table and Products table, choose productid and id respectively.
Step 4: Apply Star Schema
  • The Sales table becomes the fact table.
  • Customers and Products become dimensions tables.

After this we can:

  • Analyze sales by products
  • Build a dynamic dashboard

Conclusion

Data modeling is the backbone of effective modeling in Power BI. By understanding the fundamental concepts such as joins, relationships and schemas you can transform raw data into meaningful insights.
A well designed model improves performance and makes reports more flexible and easier to maintain.

Top comments (0)