DEV Community

Faith Njenga
Faith Njenga

Posted on

Relationships Are Hard (Except in Power BI Data Modeling)

Cover Image

INTRODUCTION

Power BI is mainly associated with the creation of beautiful, interactive dashboards and reports, but did you know that it has more to it than that? Have a seat as I explain its immense power and what great works it can achieve.

As always, I am here to break it down to a very digestible form.

For the high performance of the reports we see, solid data models are vital. Designing a model correctly ensures fast calculation speed, accurate DAX data analysis, and easy report maintenance.

Data Schemas

schema is the structural blueprint of your data model. It dictates how your data tables are organized and connected.
Before deciding on a schema, you typically break your data into two types of tables:

  • Fact Tables: The Actions (The Numbers)
    Think of a Fact Table as a continuous digital receipt log. It only cares about tracking business events and recording the raw numbers.
    Example (Streaming App): Every time someone presses play on Netflix, it logs the event. It records Numeric Data like Duration_Minutes (45) and Pause_Count (2), alongside IDs to link to details.
    The Goal: It answers "How much?" or "How many?"

  • Dimension Tables: The Context (The Text)A Dimension Table is your lookup list. It holds all the descriptive details that give meaning to your raw numbers.
    Example (Streaming App): Instead of repeating the movie title, director, release year, and genre on every single play receipt, you store it once in a Movies lookup table next to a unique Movie_ID.
    The Goal: It answers "Who?", "What?", or "Where?"

Choosing your Blueprint(Schema)

Now that you have known your Facts from your Dimensions, how do you arrange them in Power BI?
There are 3 schema types. Namely:

  1. Star
  2. Snowflake

Star Schema

The Star schema gets its name because of its shape. You place the number-heavy Fact Table in the center and surround it with your descriptive Dimension Tables like the points of a star.

  • Why use it: It provides the best query performance, reduces data redundancy, and uses one-to-many relationships that are easy for Power BI to process.

Snowflake Schema

The Snowflake Schema happens when you split your dimension tables into even smaller lookup tables(e.g., a "Product" table branching out into separate "Brand" and "Category" tables).

  • Why use it: It is useful when you need to optimize storage or map highly complex hierarchical relationships, though it can slow down report rendering.

Flat Schema

This represents a single, massive, consolidated table where all information lives together. This happens automatically when you load a single CSV or flat Excel file into Power BI.

  • Why use it: It requires no modeling effort and is perfectly fine for small, simple datasets. However, it leads to heavy data redundancy and poor performance on large datasets. Here is a visual representation of the three.

Visual rep of the 3 schemas

Relationships

The 3 Core Settings of a Relationship
Every relationship you build in Power BI is defined by three main settings:

1. Cardinality (The Type of Connection)

  • One-to-Many (1:*): The most common and efficient type. One row in your lookup table (e.g., Customers) connects to many rows in your transaction table (e.g., Sales).
  • Many-to-One (*:1): The same as one-to-many, just viewed from the opposite direction.
  • One-to-One (1:1): Links single unique rows between two tables. It is rarely used and usually means the tables should just be merged.
  • Many-to-Many (:): Links non-unique values on both sides. It should be avoided when possible because it can cause unpredictable calculations.

2. Cross Filter Direction (How the Data Flows)

  • Single Direction: The filter flows only one way—usually from the Dimension table down to the Fact table. This is the safest and fastest setting.
  • Both Directions (Bi-directional): Filters flow both ways. While powerful, it can severely slow down your reports and create ambiguous data paths.

3. Relationship Status

  • Active: The primary path Power BI uses to calculate data between two tables. Only one active relationship can exist between any two tables at a time.
  • Inactive: Secondary paths. They sit in the background and are only triggered when you specifically call them using DAX formulas (like USERELATIONSHIP). Active vs. Inactive Example If your Sales table has a Order_Date and a Ship_Date, you can only link one of them actively to your Calendar table. You would make Order_Date active for your daily sales reports, and keep Ship_Date inactive, activating it only when calculating shipping backlogs.

Power Query Joins: Merging Tables

In Power BI, joins are used to merge two tables permanently into a single, wider table during the data preparation phase.

While relationships connect separate tables in your visual model, joins physically combine your data rows in the Power Query Editor using the Merge Queries feature.

The 6 Types of Joins in Power BI

Power BI offers six different ways to combine your datasets based on a matching column:

  • Left Outer: Keeps all rows from the first table, and only matching rows from the second table. This is the most common join.
  • Right Outer: Keeps all rows from the second table, and only matching rows from the first table.
  • Full Outer(The collector): Keeps all rows from both tables. Unmatched rows display null values for the missing data.
  • Inner(The matchmaker): Keeps only rows that match in both tables. Any unmatched data is completely discarded.
  • Left Anti: Keeps rows only present in the first table that do not have a match in the second. It is perfect for finding missing records.
  • Right Anti: Keeps rows only present in the second table that do not have a match in the first.

Quick Comparison Matrix

Join Type Records Kept from Table 1 (Left) Records Kept from Table 2 (Right) Best Used For
Left Outer All Only Matches Adding descriptive columns to transactions
Right Outer Only Matches All Inverting data priorities
Full Outer All All Combining disparate budgets or targets
Inner Only Matches Only Matches Filtering for strict overlap
Left Anti Only Unmatched None Finding customers who haven't bought yet
Right Anti None Only Unmatched Finding orphaned data in secondary tables

Join vs. Relationship: What's the difference?

It is common to confuse Power Query joins with Data Model relationships. Here is how to differentiate them:

  1. Joins (Power Query): Happen during data ingestion. They alter the physical structure of your data by flattening tables together, which consumes more memory.
  2. Relationships (Data Model): Happen after the data is loaded. They keep tables separate and link them virtually, maximizing Power BI’s performance engine.

Top comments (0)