Sub topic 4
Where many-to-many comes from
This chapter assumes you can read Power BI Desktop's model view and know fact tables, dimension tables, and one-to-many relationships. It also assumes you can write basic DAX with SUM and CALCULATE. Here you learn how to recognize a true many-to-many relationship and why it breaks the usual filter flow.
The normal case: one side filters many side
In a star schema, each dimension row is unique on its key. A one-to-many relationship sends filters from the dimension (the "one" side) to the fact table (the "many" side). Select a customer, and only that customer's sales rows stay visible.
This works because every fact row points to exactly one dimension row. The key on the dimension side is unique, so the filter has a single, clear path.
What makes a relationship many-to-many
A many-to-many relationship exists when neither side has unique values for the join. One row on the left can match several rows on the right, and the reverse is also true.
A common example is bank accounts and customers:
- A joint account belongs to two or more customers.
- A customer can hold several accounts.
The business question "How much money do Ana's accounts hold?" is easy to ask. The model has no single column that answers it, because the link between accounts and customers is itself many-to-many.
Common sources of many-to-many
Many-to-many rarely comes from a design choice. It comes from the shape of the business data. Typical sources:
- Shared ownership: joint accounts, co-owned policies, projects with several managers.
- Tags and categories: a product with several tags, an article in several topics.
- Memberships: students and courses, employees and teams.
- Mismatched grain: a budget table kept by month and region, compared with sales kept by day and store. Neither table is unique on the shared column.
- Dirty keys: duplicate rows in a table you assumed was a dimension. This looks like many-to-many but is really a data quality problem.
The last item matters most in practice. Before you treat a relationship as many-to-many, check whether the "many" is real or the result of duplicates.
Checking whether a key is unique
Test uniqueness with a measure. If the two counts differ, the column has duplicates.
Duplicate Check =
COUNTROWS ( Accounts ) - DISTINCTCOUNT ( Accounts[AccountID] )A result of 0 means AccountID is unique, so a one-to-many relationship is safe. A result above 0 means some values repeat. Either clean the data or accept that the relationship is many-to-many.
A true many-to-many relationship still has repeats after cleaning, because the repeats are meaningful. A joint account appears once per owner, and each row is correct.
Why the usual model fails
Power BI relationships need a unique key on the "one" side to propagate filters in a predictable way. When both columns repeat, two things go wrong.
- No clear path. A filter on Customers has no single route to Transactions.
- Wrong totals. If the filter does reach the facts, a transaction on a joint account can be counted once for each owner.
The next chapters cover the two ways to handle this: a native many-to-many relationship and a bridge table.
Exercise
A table of product tags has one row per product and tag pair, so "ProductID" repeats. You join it to a Products table that has unique ProductIDs. Is this relationship many-to-many?
Show answer
No. Products is unique on ProductID, so the relationship is one-to-many from Products to the tags table. It becomes many-to-many only if both sides repeat the join column, for example if you also tried to join the tags table to another table that repeats ProductID.
Exercise
Your Duplicate Check measure returns 3 for a table you believed was a dimension. What should you do before choosing a many-to-many design?
Show answer
Find the duplicated keys and decide whether they are errors or valid data. If they are errors, remove them and use one-to-many. If each repeat is a real link, such as a joint owner, the relationship is truly many-to-many.