Cardinality and Cross-Filter Direction in Power BI
Cardinality is how many rows match on each end of a relationship: one, or many. Cross-filter direction is which way a slicer is allowed to walk. Single means the dimension filters the fact. Both means the filter can walk back, and that can hide cities you still wanted to see.
Friends! The relationship dialog has two settings students click and then forget. Why do they matter? They decide whether Oil filters only the sales number, or also empties the City slicer. How? We keep many-to-one and Single on a FreshBasket model, then we peek at Both with Oil, which exists only in Mumbai. Pune must not vanish by accident.
मित्रांनो! Relationship dialog मध्ये दोन settings असतात, विद्यार्थी क्लिक करून विसरतात. का महत्त्वाच्या? त्या ठरवतात Oil फक्त sales number फिल्टर करतो का, की City स्लायसरही रिकामा करतो. कसे? FreshBasket मॉडेलवर many-to-one आणि Single ठेवायचे, मग Oil सह Both बघायचे. Oil फक्त Mumbai मध्ये आहे. Pune चुकून गायब होता कामा नये.
मित्रों! Relationship dialog में दो settings होती हैं, छात्र क्लिक करके भूल जाते हैं. क्यों ज़रूरी? वे तय करती हैं Oil सिर्फ sales number फ़िल्टर करता है, या City स्लाइसर भी खाली कर देता है. कैसे? FreshBasket मॉडल पर many-to-one और Single रखें, फिर Oil के साथ Both देखें. Oil सिर्फ Mumbai में है. Pune गलती से गायब नहीं होना चाहिए.
Quick answer
Vertical path:
- Double-click the relationship line in Model view.
- Cardinality: many-to-one (Sales many, Store one) for a normal star.
- Cross-filter direction: Single unless you have a written reason for Both.
- Product = Oil (only Mumbai) with Single: sales card 50, City slicer still lists Pune.
- The same slicer with Both can drop Pune, because the filter walks back to Store.
- Need Both for one measure only? Use CROSSFILTER inside CALCULATE. Do not change the whole model.
Single: dimension → fact
Both: dimension ⇄ fact (surprises live here)
Real example: Oil is only in Mumbai
Sales:
| Order | City | Product | Amount |
|---|---|---|---|
| A | Mumbai | Rice | 100 |
| B | Mumbai | Oil | 50 |
| C | Pune | Rice | 40 |
Product is a dimension (Rice, Oil). Store is a dimension (Mumbai, Pune). Sales is the fact. Both relationships are many-to-one, from Sales to the dimension.
What Single does when the reader picks Oil:
- Product keeps the Oil row.
- The filter walks into Sales. Only order B matches.
- Number out: 50.
- The City slicer is not filtered by that walk. Pune is still on the list.
- If the reader then also picks Pune, the card can go blank. That is honest: Pune did not sell Oil.
What Both does on the Product relationship:
- Oil still keeps order B.
- The filter also walks back from Sales to Store.
- Store keeps only Mumbai, because order B is Mumbai.
- The City slicer can drop Pune even though you did not touch City.
- Readers think the shop closed in Pune. The setting closed it.
That is why the default is Single.
What do I need before this guide?
- A real line already created (relationships).
- Course: Relationships (cardinality and cross-filter direction live in that lesson).
Before and after (look at the tables first)
Before - Both walks back. Both hid Pune
आधी (Before) — Both मागे चालतो. Both ने Pune लपवला.
पहले (Before) — Both पीछे चलता है. Both ने Pune छिपा दिया.
After - Single direction. Single. Card 50. List stays honest.
नंतर (After) — Single direction. Single. Card 50. यादी प्रामाणिक राहते.
बाद में (After) — Single direction. Single. Card 50. सूची ईमानदार रहती है.
How to set the dialog
The relationship dialog sets cardinality (how many rows match) and cross-filter direction (which way a slicer walks).
Relationship dialog cardinality (किती rows जुळतात) आणि cross-filter direction (स्लायसर कोणत्या बाजूने जातो) सेट करतो.
Relationship dialog cardinality (कितनी rows जुड़ती हैं) और cross-filter direction (स्लाइसर किस ओर जाता है) सेट करता है.
- Model view. Double-click the Sales–Store line (or Manage relationships, then Edit).
- Cardinality: Many to one (*:1). The many side is the fact.
- If Power BI offers one-to-one, the “many” column is actually unique. Check the grain before you celebrate.
- If it offers many-to-many, stop. One side should be unique. Fix the key, then come back.
- Cross-filter direction: Single.
- Leave “Make this relationship active” on for the main path.
- Save. Repeat for Product and Date.
One-to-one is rare here. Employee and Employee Details are the textbook pair, and they are usually happier as one table. Do not use one-to-one to glue a fact to a dimension.
Single, Both, and one measure
Single lets Product filter Sales only. Both can also hide Pune on the City slicer when Oil exists only in Mumbai.
Single Product ला फक्त Sales फिल्टर करू देतो. Both City स्लायसरवरून Pune लपवू शकतो जेव्हा Oil फक्त Mumbai मध्ये असतो.
Single Product को सिर्फ Sales फ़िल्टर करने देता है. Both City स्लाइसर से Pune छिपा सकता है जब Oil सिर्फ Mumbai में हो.
Sometimes a manager wants the City slicer to show only cities that sold the selected product. That is a real request. Two calm options:
- A visual-level filter on the City slicer: [Total Sales] is not blank. The model direction stays Single. Oil then shows Mumbai only, because Pune’s Oil sales are blank.
- A measure that turns Both on for that question only:
Sales Both Ways =
CALCULATE (
[Total Sales],
CROSSFILTER ( Sales[Product ID], Product[Product ID], Both )
)
- The model line stays Single for every other visual.
- This measure borrows Both for one calculation.
- You can explain it in a sentence. A silent Both on the relationship is harder to debug at 6 pm.
“Apply security filter in both directions” is a row-level security switch. Leave it off until the security guide says you need it. It is not a decoration.
Numbers to memorise
| Choice | Oil selected | Sales card | City slicer |
|---|---|---|---|
| Single | Oil | 50 | Mumbai and Pune still listed |
| Both on Product | Oil | 50 | Pune may disappear |
| No product filter | — | 190 | Both cities |
Rice is in both cities (100+40). An Oil test is the one that exposes Both. Test with a value that exists on only one side.
Mistakes and calm fixes
| Symptom | Likely cause | Fix |
|---|---|---|
| City slicer loses Pune | Cross-filter Both | Set Single, or filter the slicer on non-blank sales |
| Cardinality stuck on many-to-many | Duplicate keys | Unique dimension key |
| Two actives refused | Two paths between the same tables | One active line; see USERELATIONSHIP |
| Totals change after “just a checkbox” | Direction changed the filter path | Put Single back and retest Oil |
Ravindra Bagale's Tip
Interview line: “Cardinality is many-to-one from fact to dimension. Cross-filter stays Single. If I need Both, I use CROSSFILTER in one measure, not on every relationship.” Got it?
Ravindra Bagale's Tip – मराठी
Interview line: “Cardinality fact कडून dimension कडे many-to-one. Cross-filter Single राहतो. Both हवे असल्यास मी प्रत्येक relationship वर नाही, एका measure मध्ये CROSSFILTER वापरतो.” समजलं का?
Ravindra Bagale's Tip – हिंदी
Interview line: “Cardinality fact से dimension की ओर many-to-one. Cross-filter Single रहता है. Both चाहिए तो मैं हर relationship पर नहीं, एक measure में CROSSFILTER इस्तेमाल करता हूँ.” समझ में आया?
Practice task
- Build the three-row sales table with Rice and Oil.
- Set both relationships to many-to-one and Single.
- Select Oil. Confirm 50, and confirm Pune is still in the City slicer.
- Flip Product to Both. Watch the City slicer.
- Put Single back. Write one sentence about what changed.
Got it? Cardinality says how many rows match. Cross-filter direction says which way the slicer walks. Keep Single. Next: star shape versus a snowflake with an extra hop. Let us go ahead.
समजलं का? Cardinality सांगते किती rows जुळतात. Cross-filter direction सांगते स्लायसर कोणत्या बाजूने जातो. Single ठेवा. पुढे: star shape विरुद्ध extra hop असलेला snowflake. आता पुढे जाऊया.
समझ में आया? Cardinality बताती है कितनी rows जुड़ती हैं. Cross-filter direction बताती है स्लाइसर किस ओर जाता है. Single रखें. आगे: star shape बनाम extra hop वाला snowflake. अब आगे बढ़ते हैं.
Frequently asked questions
What is cardinality?
How many rows match on each end: one-to-many, one-to-one, or many-to-many.
What is cross-filter direction?
Which way a filter is allowed to walk along the relationship.
Why keep Single?
Both can hide dimension values, such as dropping Pune when you only picked a product.
When is Both useful?
When a slicer should list only items that have sales. Try a visual filter first, or CROSSFILTER on one measure.
What is one-to-one for?
Rare pairs such as Employee and Employee Details. Usually merge them into one table.
Course lesson?
Relationships, in the data modelling chapter, covers cardinality and direction.