⚡0 XP🔥0

Data Modelling - Star Schema and Relationships

Lesson 3 of 6 ⏱ 5 min read ❓ 5-question quiz

Design a proper data model - fact and dimension tables, the star schema, relationships, cardinality and filter direction, keys, and modelling the shop database (orders, order items, customers, products, dates).

Why data modelling matters#

Real data comes in several tables: orders, items, customers, products. You could merge everything into one wide table, but that wastes memory, repeats data and makes calculations confusing. Power BI is designed for a data model of related tables.

Fact and dimension tables#

Fact table Dimension table
Contains events / transactions - numbers to aggregate descriptions - who, what, where, when
Examples order items, payments, attendance, website visits customers, products, stores, dates, employees
Rows many (grows daily) fewer (changes slowly)
Columns keys + numeric measures (quantity, amount) key + attributes (name, category, city)

The star schema#

                    ┌─────────────┐
                    │   Date      │
                    │ Date (key)  │
                    │ Year, Month │
                    └──────┬──────┘
                           │ 1
┌─────────────┐   1        │ *        1  ┌──────────────┐
│ Customers   ├──────* ┌───┴────────┐ *─┤  Products    │
│ customer_id │        │  Sales     │   │ product_id   │
│ name, city  │        │ (fact)     │   │ name,category│
│ segment     │        │ order_id   │   │ price, cost  │
└─────────────┘        │ customer_id│   └──────────────┘
                       │ product_id │
                       │ order_date │
                       │ quantity   │
                       │ discount   │
                       └────────────┘

One central fact table surrounded by dimension tables - it looks like a star.

हिंदी में समझें

Star schema = बीच में एक fact table (लेन-देन / transactions - जैसे हर बिकी हुई चीज़ की row, quantity, amount) और उसके चारों ओर dimension tables (विवरण - customer कौन, product क्या, तारीख़ कब, जगह कहाँ)।

फ़ायदा: customer का नाम-शहर एक ही बार customers table में रहता है, हर order में दोहराना नहीं पड़ता। Model छोटा, तेज़ और DAX आसान होता है। Power BI में यही design सबसे अच्छा माना जाता है।

Relationships#

A relationship connects a key column in a dimension to the matching column in a fact table.

Property Options Recommended
Cardinality one-to-many (1:*), one-to-one (1:1), many-to-many (*:*) 1:* from dimension to fact
Cross-filter direction Single, Both Single (dimension filters fact)
Active / inactive one active path between two tables use inactive + USERELATIONSHIP for alternate dates

Create relationships in Model view by dragging a key from one table onto the matching key in another, or Home → Manage relationships.

Common Mistake

"Both" direction filtering and many-to-many relationships can produce confusing totals and slow models. Use them only when you understand why you need them.

Hands-on: model the shop database#

Data

shop_csv.zip - customers.csv, products.csv, orders.csv, order_items.csv, employees.csv (the same shop database you queried in the SQL module).

Step 1 - Load the tables#

Get data → Folder (or Text/CSV for each file) → load customers, products, orders, order_items.

Step 2 - Create a single fact table#

orders (one row per order) and order_items (one row per item) are both "fact-like". A clean approach: in Power Query, merge order_items with orders on order_id (Left Outer) and expand customer_id, order_date, status, payment_mode. Name the result Sales (405 rows - one per item). Disable load on orders and order_items.

Step 3 - Add the Date table#

Use the DAX calendar from the previous lesson (2024-01-01 to 2025-12-31) and mark it as a date table.

Step 4 - Relationships (Model view)#

From (one side) To (many side)
Customers[customer_id] Sales[customer_id]
Products[product_id] Sales[product_id]
Date[Date] Sales[order_date]

Step 5 - Hide technical columns#

In the Sales table, hide customer_id, product_id, item_id (right-click → Hide in report view). Report users should pick customer and product attributes from the dimension tables, not from the fact.

Step 6 - Test#

Build a table visual: Products[category], Customers[segment], Count of Sales[item_id]. If numbers repeat identically for every row, a relationship is missing or wrong.

Check your model
  • Sales fact: 405 rows (one per order item), covering 200 orders.
  • Products → Sales and Customers → Sales are 1:* with single direction; Date → Sales on order_date.
  • Count of items by category should differ by category (no identical repeated totals).
  • 4 customers have no sales rows - with a Customers table visual you can still list them (dimension shows all members when "Show items with no data" is on).

Calculated columns vs measures (preview)#

Calculated column Measure
Computed at refresh, stored per row at query time, for the current filter
Uses memory yes no
Use for row attributes you slice/filter by (price band, age group) numbers you aggregate (Total Sales, Margin %)

Rule of thumb: if you'll put it on an axis or slicer → column; if you'll put it in Values → measure.

Modelling best practices#

  1. Star schema: facts in the middle, dimensions around, 1:* single-direction relationships.
  2. One Date table, marked as date table, related to every date column in facts.
  3. Remove or hide columns not needed in reports; hide foreign keys.
  4. Use integer keys where possible; avoid text keys with spaces.
  5. Name tables and columns in business language (Sales, Customer Name).
  6. Keep calculations as measures, not calculated columns, unless you need to slice by them.

Summary#

  • Facts hold events and numbers; dimensions hold descriptions - arrange them as a star.
  • Relationships connect dimension keys to fact keys: one-to-many, single direction.
  • Model the shop CSVs: Sales fact (items + order info), Customers, Products, Date.
  • Columns for slicing, measures for aggregating.

Quick Quiz

Q1.

In a star schema, what does a fact table contain?

Q2.

The relationship from Customers (one row per customer) to Orders (many rows per customer) is...

Q3.

By default, filters flow...

Q4.

Why is a star schema better than one huge flat table for Power BI?

Q5.

A relationship line shows "*" on both ends. This means...