Sub topic 1
Starting point: facts and dimensions
This chapter sets up the vocabulary and the sample model used in the rest of the tutorial. Every many-to-many problem in Power BI starts from a star schema, so it helps to be precise about what that is and how filters behave in it.
Prerequisites
This chapter assumes you can:
- Open Power BI Desktop and switch between Report view, Table view, and Model view.
- Create a one-to-many relationship by dragging one column onto another in Model view.
- Write a basic DAX measure with
SUMandCALCULATE. - Tell a fact table from a dimension table at a basic level. This chapter reviews the idea in more detail.
You do not need to know anything about bridge tables or many-to-many cardinality yet. Those come in later chapters.
What a star schema is
A star schema is a way of arranging tables for analysis. It has two kinds of tables.
- A fact table records events or measurements. Each row is one thing that happened, such as a transaction, a sale, or a shipment. Fact tables are usually long and narrow. They hold numeric columns you aggregate (such as
Amount) and key columns that point to dimensions. - A dimension table describes the things you group and filter by. Each row is one entity, such as a customer, a product, or a date. Dimension tables are usually shorter and wider. They hold descriptive columns (such as
CustomerNameorRegion) and one key column that identifies each row.
The name comes from the diagram. The fact table sits in the middle, and each dimension connects to it like a point of a star.
The arrows show the direction in which filters travel. A selection on a dimension narrows the rows of the fact table, and a selection on the fact table does not narrow the dimension. The next sections explain why.
The sample model
The tutorial uses a small banking model. Its tables are:
| Table | Kind | Key columns | Purpose |
|---|---|---|---|
| `Transactions` | Fact | `TransactionID`, `AccountID` | One row per money movement. Holds `Amount`. |
| `Accounts` | Dimension | `AccountID` | One row per account. |
| `Customers` | Dimension | `CustomerID` | One row per customer. |
| `AccountCustomer` | Source list | `AccountID`, `CustomerID` | Says which customers are linked to which accounts. |
For now, focus on Transactions and Accounts. Accounts[AccountID] is unique, so each account appears once. Transactions[AccountID] repeats, because an account has many transactions. This is a textbook one-to-many relationship: one account, many transactions.
Customers and AccountCustomer are included from the start because they cause the trouble later. A joint account belongs to several customers, and one customer can hold several accounts. Neither side is "one" anymore. Later chapters cover that case. In this chapter, set it aside and look at why the simple case works.
Why a unique key matters
A dimension table works as a filter source because its key is unique. When the key is unique, each fact row matches at most one dimension row, so there is no ambiguity about which dimension row a fact row belongs to.
You can check this in Power BI Desktop with a quick calculated table. This one returns any account key that appears more than once in Accounts:
Duplicate Account Keys =
FILTER (
SUMMARIZE ( Accounts, Accounts[AccountID] ),
CALCULATE ( COUNTROWS ( Accounts ) ) > 1
)If the dimension is well formed, this table is empty. If it returns rows, the key is not unique, and Power BI will not let you create a one-to-many relationship on that column. You would need to clean the data or build a unique list of keys first. Chapter 7 shows how to build that list for a bridge.
Delete the check table after you run it. It is a diagnostic, not part of the model.
How a filter travels in a star schema
A filter in Power BI is a restriction on which rows are visible when a calculation runs. Filters come from slicers, from visuals (the row or axis value of a chart or matrix), and from CALCULATE. A relationship tells the engine how to pass a filter from one table to another.
In a one-to-many relationship, the default direction is from the "one" side to the "many" side. This is called single direction filtering. Take this measure:
Total Amount = SUM ( Transactions[Amount] )Put Accounts[AccountName] on the rows of a table visual and [Total Amount] as the value. For each row of the visual, the engine does this:
- It keeps only the
Accountsrow for that name. - It follows the relationship to
Transactionsand keeps only rows with a matchingAccountID. - It sums
Amountover those remaining rows.
The result is the total for that one account. The sum of all rows equals the grand total, because every transaction belongs to exactly one account.
Why filters do not travel the other way
With single direction filtering, selecting rows in Transactions does not filter Accounts. If you put a Transactions[TransactionID] slicer next to a list of accounts, the list still shows all accounts. This is intended. Fact tables are large, and letting them filter dimensions would be expensive and often confusing.
Power BI does let you change the direction to both. That setting, and its costs, is the topic of the cross-filter direction chapter. For now, keep the default.
Common mistakes in a star schema
These errors cause most of the confusing results you will see later.
- Filtering on a fact table column. If you put
Transactions[AccountID]on a visual instead ofAccounts[AccountName], the visual works, but slicers built on other dimensions may behave unexpectedly. Build visuals and slicers from dimension columns. - Duplicate keys in a dimension. Duplicates block the one-to-many relationship, or they silently break the "one" side if you work around the error.
- Blank keys. If a fact row has an
AccountIDthat does not exist inAccounts, Power BI groups it under a blank row in visuals. The amounts are not lost, but they show up under "(Blank)". Check for this when totals look correct but a blank category appears. - Mixing grains. Grain means what one row represents. If one fact table has a row per transaction and another has a row per month, do not join them directly. Connect both to shared dimensions.
Checking your model
Before you move on, confirm that your model matches this checklist.
- Each dimension has one column with a unique value per row.
- Each relationship between a dimension and the fact table is one-to-many, with the "one" end on the dimension.
- The cross-filter direction on each relationship is single, from dimension to fact.
- The grand total of
[Total Amount]equals the sum of the values for every account, with no blank category.
When all four hold, filters behave predictably, and the totals are additive. The rest of the tutorial shows what changes when a dimension on one side of a relationship stops having unique keys.
Summary
- A fact table holds events and numbers. A dimension table holds descriptions and a unique key.
- A one-to-many relationship passes filters from the dimension to the fact table by default.
- Unique dimension keys make every fact row belong to exactly one dimension row, which keeps totals additive.
- The sample model adds
CustomersandAccountCustomer, which break the one-to-many pattern. The next chapters examine how.
Exercise
In the sample model, a slicer on Accounts[AccountName] is set to "Savings". Which rows of Transactions does [Total Amount] sum, and why does a slicer on Transactions[TransactionID] not change the list of accounts shown in a separate account slicer?
Show answer
[Total Amount] sums only the Transactions rows whose AccountID matches the "Savings" account, because the one-to-many relationship passes the filter from Accounts (the "one" side) to Transactions (the "many" side). A slicer on Transactions[TransactionID] does not change the account slicer because the relationship uses single direction filtering, so filters do not travel from the fact table back to the dimension.
Exercise
A table visual grouped by Accounts[AccountName] shows a row labeled "(Blank)" with a non-zero [Total Amount]. What is the most likely cause, and where do you fix it?
Show answer
Some Transactions rows have an AccountID that does not exist in Accounts. Power BI cannot match them to a dimension row, so it groups them under blank. Fix it in the data: add the missing account to Accounts or correct the bad keys in Transactions, then refresh.