DEV Community

Cover image for Understanding Data Modelling in Power BI: Joins, Relationships, and Schemas Explained
Anthony Kibet
Anthony Kibet

Posted on

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

Data modeling is like building a well-organized library πŸ“š. It helps us connect different pieces of information in a way that makes analysis easy and meaningful. In Power BI, data modeling is the process of defining how tables relate to each other, making sure data flows smoothly for reporting and insights. It involves creating relationships, understanding joins, and designing schemas β€” all to turn raw data into useful stories.


What is Data Modeling?

Imagine collecting data from different sources: sales data, customer info, products, and more. Data modeling arranges these data pieces in a logical way. Instead of having all data jumbled together, it structures it so you can analyze relationships: who bought what, when, and why? In Power BI, this is achieved through establishing relationships between tables, which allows you to filter, aggregate, and drill down into your data efficiently.


SQL Joins: (Data Combination)

SQL joins are ways to combine data from two or more tables based on related columns. Let's explore the common joins with simple examples:

1. INNER JOIN

  • What it does: Only shows rows with matching values in both tables.
  • Example: Find customers who made purchases. Only customers with sales records appear. -alt text

2. LEFT JOIN (or LEFT OUTER JOIN)

  • What it does: Shows all rows from the left table, plus matches from the right table. If there's no match, you still see the left table row, but with blank info on the right.
  • Example: List all customers, even those who didn't buy anything (show blank for sales). alt text

3. RIGHT JOIN (or RIGHT OUTER JOIN)

  • What it does: Opposite of LEFT JOIN; shows all rows from the right table plus matched rows from the left. alt text

4. FULL OUTER JOIN

  • What it does: Combines everything from both tables; shows all matches and non-matches from both sides. alt text

5. LEFT ANTI JOIN

  • What it does: Shows rows from the left table that do not have a match in the right.
  • Example: Customers who haven't made any purchase.

6. RIGHT ANTI JOIN

  • What it does: Rows from the right table with no match in the left.
  • Example: Sales records with no customer info.

Power BI Relationships: Building Connections 🌐

Unlike SQL joins, Power BI relationships are persistent links between tables that don't change unless you edit them. Here’s what you need to know:

  • Cardinality: How many related records exist:

    • 1:M (One-to-Many): One record in the first table relates to many in the second. (e.g., one customer β†’ many orders)
    • M:M (Many-to-Many): Multiple records related to multiple. Requires bridging tables.
    • 1:1 (One-to-One): One record relates to only one record.
  • Active vs Inactive Relationships: Active relationships are used by default when you analyze data, while inactive ones are stored but not automatically used. You can activate an inactive link when needed.

  • Cross-Filter Direction: How filters flow:

    • Single direction: filters go one way.
    • Both directions: filters flow both ways, useful for complex models.

Fact and Dimension Tables: The Building Blocks

  • Fact Tables: Store measurable data, like sales amount, quantity sold. Usually large.
  • Dimension Tables: Store descriptive info, like customer names, product categories. Usually smaller.

Schemas:

  • Star Schema: Fact table connected directly to dimension tables. Used for simplicity and fast querying.
  • Snowflake Schema: Dimension tables normalized into sub-tables, reducing data redundancy.
  • Flat Table (DLat): All data in one big table, but less efficient and harder to maintain.

Role-Playing Dimensions: Multiple Uses of a Single Dimension

Some dimensions, like Date, can be used to filter sales date, ship date, or invoice date. In Power BI, you relate the same Date table to multiple date fields to reuse.


Top comments (0)