Ravindra BagaleCourses & study guides Track your progress

Guides

Relationships in Power BI: One to Many and Many to Many

A relationship is the line that connects two tables on a matching key. One-to-many means one store row can match many sales rows. Many-to-many means neither column is unique, and totals can double if you are not careful.

Friends! A City slicer that changes nothing is usually a missing line, not a broken measure. Why? Filters travel along relationships. How? We relate FreshBasket Sales to Store on Store ID, one store to many sales, and Mumbai stays 150. Slow and clear.

Quick answer

Vertical path:

  1. Fact Sales holds Store ID plus Amount. Store holds Store ID plus City.
  2. In Model view, drag Sales[Store ID] onto Store[Store ID].
  3. The many side (*) sits on Sales. The one side (1) sits on Store.
  4. Keep cross-filter direction Single for this first line.
  5. A City slicer = Mumbai keeps 100 + 50 and drops Pune. Total 150.
  6. If both columns repeat, do not shrug and accept many-to-many. Make one side unique.
Store (1) ——< Sales (*)
City filter walks from Store into Sales

Real example: three sales, two stores

Sales (many rows):

Order Store ID Amount
A S1 100
B S1 50
C S2 40

Store (one row per store):

Store ID City Channel
S1 Mumbai Online
S2 Pune Store

What the relationship does:

  1. Store ID S1 is unique on Store. It appears twice on Sales. That is one-to-many.
  2. Slicer City = Mumbai keeps store S1.
  3. Sales rows A and B stay. Row C leaves.
  4. Number out: 150.
  5. Slicer City = Pune keeps S2 only. Number out: 40.
  6. No slicer: 190.

There is no City column on Sales. The line carries the filter. That is the whole point of the relationship.

What do I need before this guide?

Before and after (look at the tables first)

Before relationships Sales rows with city text and no relationship.

Before - No relationship. No line. A slicer cannot travel.

After relationships Store dimension and sales totals after the relationship.

After - One store, many sales. One-to-many. Mumbai = 150

How to create the line

One to many One to many. Store S1 Mumbai (1) | Sales 100 and 50 (*) City = Mumbai → 150 One to many Store S1 Mumbai (1) | Sales 100 and 50 (*) City = Mumbai → 150

One store row (1) matches many sales rows (*). The City slicer walks from Store into Sales.

  1. Open Model view.
  2. Confirm Store ID has the same data type on both tables (text with text, or number with number).
  3. Drag Sales[Store ID] onto Store[Store ID].
  4. Read the labels: * on Sales, 1 on Store.
  5. Double-click the line. Cardinality should be many-to-one. Cross-filter direction Single. Active ticked.
  6. Hide Store ID from report view. Authors should pick City, not the key.
  7. Put City on a slicer and [Total Sales] on a card. Mumbai must read 150.

If Power BI already drew a line because the names matched, still open it. Autodetect can pair the wrong columns.

Many-to-many: when the line is a warning

Many to many warning Many to many warning. Sales City repeats. Targets City repeats. A direct link can double totals. Fix: City table with one row per city. Mumbai sales stay 150. Targets stay 200. Many to many warning Sales City repeats. Targets City repeats. A direct link can double totals. Fix: City table with one row per city. Mumbai sales stay 150. Targets stay 200.

If City repeats on both Sales and Targets, totals can double. Put a unique City table in the middle.

Imagine a Targets sheet with two Mumbai rows (Online target and Store target). City is not unique there. City is not unique on Sales either.

City Channel Target
Mumbai Online 120
Mumbai Store 80
Pune Online 60

If you relate Sales[City] to Targets[City], both sides are many. A visual can repeat rows and a total can look bigger than 190. That is not “advanced modelling”. That is a grain problem.

  1. Build a small City table with one row per city: Mumbai, Pune.
  2. Relate Sales to City (many-to-one) and Targets to City (many-to-one).
  3. The City slicer then filters both tables through the one side.
  4. Mumbai sales stay 150. Mumbai targets stay 200 (120+80). They do not multiply each other.

Power BI can create a many-to-many relationship. Use it only when a teacher has shown the grain and you have checked the total. Beginners should fix the key instead.

A second date on Sales (order date and delivered date) is a different problem: two lines to the same Date table. Only one stays active. The dashed line is taught in USERELATIONSHIP. Do not delete it because it looks dotted.

What the filter actually walks

  1. The slicer filters the one side first (Store or City).
  2. The relationship keeps fact rows whose key still matches.
  3. The measure sums what remains.
  4. A filter does not jump to a table that has no path.
  5. A blank row in a slicer often means a Sales key with no Store match. Fix the key. Do not hide the blank and pretend the model is clean.

Mistakes and calm fixes

Symptom Likely cause Fix
Slicer does nothing No line, or the line is inactive Create an active relationship on the key
Totals too big Many-to-many or duplicate keys on the “one” side Make the dimension key unique
“Cannot create relationship” Types differ, or both columns repeat Match types; fix uniqueness
Blank in the slicer Fact key missing from the dimension Clean keys or add the missing store

Ravindra Bagale's Tip

Interview line: “I relate the fact to the dimension many-to-one on a unique key. If both sides repeat, I add a bridge dimension instead of trusting a many-to-many total.” Got it?

Practice task

  1. Load the three sales rows and the two store rows.
  2. Create the relationship on Store ID.
  3. Prove Mumbai 150 and Pune 40.
  4. Add a second Mumbai row on a Targets table and see why City cannot be the key on both sides.
  5. Add a City table with unique names and relate both facts to it.

Learn it properly

Course lesson:

Related: Star schema · Inactive relationships (USERELATIONSHIP)

Got it? A relationship is the line. One store, many sales. Mumbai stays 150 because the filter walks that line. Next: what the 1 and * labels mean, and which way the filter is allowed to walk. Let us go ahead.

Frequently asked questions

What is a Power BI relationship?

A line between two tables on a matching key so a slicer on one table can filter the other.

What is one-to-many?

One row on the dimension (one store) matches many rows on the fact (many sales).

What is many-to-many?

Neither column is unique. Totals can repeat. Prefer a dimension where the key is unique.

Why does my slicer do nothing?

There is no active relationship, or the columns are different types.

Why is there a blank in the slicer?

A fact key has no match in the dimension. Fix the key. Do not hide the blank and ignore it.

Where is the inactive date line taught?

In the USERELATIONSHIP guide. A dashed line is a second path, not a broken one.