Stop 06 · Data ModelingTopics · 6/9

Many-to-Many Relationships

Part of the Power BI Roadmap

In short

Targets come per category per month, but sales come per product per day. Neither table has a unique Category column. Many-to-many relationships and bridge tables are how you connect them without wrong totals.

When neither side has unique keys, such as sales targets set per category per month against daily sales, you either use a many-to-many relationship or a bridge table of unique values. Both need care because totals can surprise you.

The jaadu holds a big board listing each club once, with ribbons running from it to a crowd of students on one side and a stack of club target sheets on the other.

Think of it like this

Students and clubs

A student can join many clubs and a club has many students. You can't write one club on a student's card. Schools keep a register of student-club pairs, or a master list of clubs everyone points to. That master list is the bridge table.

Watch it happen

A Category bridge

Category (unique)
Product
Targets
Sales

1/4Build a small table with each category once: Snacks, Beverages, Dairy.

The big ideas

What you need to know

When neither side is unique

Product has many rows per category and Targets has many months per category. That's many-to-many.

Bridge table

A table of unique values both sides relate to. It turns one *:* into two clean 1:* relationships.

Direct *:* option

Power BI can relate the two tables directly as many-to-many. It works, but filter behaviour and totals need careful checking.

Mind the grain

Targets are monthly. Showing them by day will repeat or blank them, so report targets at month level.

See it in code

Walk through the code

dax
1Category =2DISTINCT (3    UNION (4        DISTINCT ( 'Product'[Category] ),5        DISTINCT ( Targets[Category] )6    )7)8 9Target Amount = SUM ( Targets[Target] )10 11Achievement % = DIVIDE ( SUM ( Sales[Amount] ), [Target Amount] )

1/3Collect categories from both tables, so a category with a target but no products yet still appears. The outer DISTINCT removes repeats.

A calculated bridge table of unique categories, plus measures that compare sales to targets.

Save yourself the pain

Common mistakes

Oops

Relating Targets directly to Sales on Category.

Do this instead

Sales has no Category column of its own and keys must make sense. Go through a Category dimension or bridge.

Oops

Showing monthly targets on a daily axis.

Do this instead

Targets exist only at month and category level. Show them at that grain or allocate them on purpose.

Your mission

Sales vs target

~30 min

Quick check

What problem does a bridge table solve?

Go deeper

  1. 1Model monthly category targets against daily sales using a shared Category dimension.
  2. 2Build the same thing with a bridge table and compare the results.
  3. 3Check grand totals carefully whenever a many-to-many path is involved.

More topics at this stop

Stuck on this topic? Ask an Insider

Get 1:1 guidance from people who've walked this exact path — on the InsideEdge app.

Download
InsideEdge