Chapter 6 — Power BI: Data Modeling & Relationships
📚 Chapter Overview
A great report is built on a solid data model. In this chapter, you will learn how to import data into Power BI, create relationships between tables (Star Schema), and write basic DAX formulas for custom calculations.
Learning Objectives:
- Import data from multiple sources (Excel & MySQL).
- Master "One-to-Many" relationships.
- Understand the difference between Measures and Calculated Columns.
6.1 The Star Schema
Part 1 — Definition
A Star Schema is an industry-standard way to organize data. It consists of one large Fact Table (containing numbers like sales) surrounded by several Dimension Tables (containing details like product info, dates, and locations). Connecting these tables is called "Modeling".
Part 2 — Relationship Types
- 1:* (One-to-Many): One product can appear in many sales. This is the most common and recommended type.
- Primary Key: A unique ID in a table.
- Foreign Key: The ID in another table used for linking.
Part 3 — Example
Problem: Connect a "Sales" table to a "Customer" table.
- Load both tables into Power BI Desktop.
- Go to the Model View.
- Drag
customer_idfrom the Customer table tocustomer_idin the Sales table.
Observation: You can now filter Sales charts using Customer attributes like "Country" or "Gender".
Part 4 — Video
Video: Coming Soon
6.2 DAX Basics
Part 1 — Definition
DAX (Data Analysis Expressions) is the formula language for Power BI. It is similar to Excel formulas but much more powerful. You use DAX to create **Measures**, which are calculations that update dynamically as you filter your report.
Part 2 — Syntax
Total Sales = SUM(Sales[Revenue])
Profit Margin = DIVIDE([Profit], [Total Sales], 0)
Part 3 — Example
Problem: Calculate "Year-to-Date" (YTD) Sales.
Sales YTD = TOTALYTD(SUM(Sales[Amount]), 'Date'[Date])
Observation: Measures don't take up space in the file; they are calculated "on the fly" when you interact with the report.
Part 4 — Video
Video: Coming Soon
🏆 Chapter Challenge
Challenge Objective
Build a "Multi-Source Data Model".
Requirements
- Connect Power BI to an Excel file (Product Data) and a MySQL table (Sales Data).
- Create a relationship between them using
ProductID. - Create a DAX Measure for "Total Transactions" using
COUNTROWS.
Step-by-Step Process
- Use "Get Data" for both sources.
- Verify the relationship line in Model View.
- Write the DAX formula.
- Drag the measure into a "Card" visual to verify the number.
Expected Deliverables
- The Power BI File (.pbix).