Sub topic 13
Choosing the right approach
This chapter assumes you can read Power BI model view, know the difference between fact and dimension tables, understand one-to-many relationships, and can write basic DAX with SUM and CALCULATE. Earlier chapters covered cardinality, cross-filter direction, the native many-to-many relationship, and the bridge table pattern. Here you decide which one to use for a given model.
The decision in one sentence
Use a bridge table when the model needs to stay predictable, reusable, and easy to explain. Use a native many-to-many relationship when you need a quick link between two tables and you accept its limits. Use CROSSFILTER or TREATAS to cover the gaps in either choice, one measure at a time.
What each option does
The three approaches differ in where the many-to-many logic lives.
- Native many-to-many puts the logic in one relationship. Two tables are joined directly on a column that has duplicates on both sides.
- Bridge table puts the logic in a third table with unique key pairs. Two ordinary one-to-many relationships connect it to the two dimensions.
- DAX-only approaches put the logic in a measure. The model has no relationship between the tables, or the relationship is changed for one calculation.
The sections below compare them.
Comparing the options
| Question | Native many-to-many | Bridge table | `TREATAS` measure |
|---|---|---|---|
| Extra table needed | No | Yes | Only if you want a bridge to supply the values |
| Relationships in the model | One many-to-many | Two one-to-many | None between the two tables |
| Filter direction | Single or both | Usually both on the dimension side | Not applicable |
| Works for every measure automatically | Yes | Yes, if direction is set | No, each measure must include it |
| Weights or extra attributes on the link | Not possible | Possible | Possible if a table holds them |
| Easy to see in model view | Yes | Yes | No, the logic is hidden in DAX |
| Risk of double counting | Present | Present | Present |
Note the last row. No approach removes double counting. If one account belongs to two customers, then summing amounts per customer and adding the rows will count that account twice. The choice only changes where you control it.
Criteria for choosing
Work through these questions in order.
1. Is the relationship truly many-to-many?
Check first. If one side is actually unique once you clean the data, a normal one-to-many relationship is better than either option. Duplicate keys that come from data entry errors are a data problem, not a modelling choice. Fix them upstream, or remove them with DISTINCT or in Power Query.
2. Does the link need its own data?
If the link carries information, use a bridge. Examples are an ownership percentage, an effective date range, or a role such as "primary owner". A native many-to-many relationship has nowhere to store those columns. A bridge table has a row for each pair, so you can add a Weight column and use it in measures.
3. Are both sides already unique somewhere?
A native relationship joins on a column that is not unique in either table. The engine handles it, but it uses a weaker kind of relationship. A bridge needs a unique column on each dimension, such as CustomerID in Customers and AccountID in Accounts. If you have those dimensions already, a bridge is simple to build. If you have no dimension for one side, a native relationship between the two fact-like tables may be the only quick option.
4. How many reports and authors will use the model?
A bridge is visible and follows the usual star-schema shape. New report authors can read it. A TREATAS measure has to be remembered and repeated. If many people write measures against the model, an approach that needs a special pattern in every measure will eventually be missed in some of them, and the numbers will disagree.
5. How large is the model?
Both relationship types add work when filters cross them. A native many-to-many relationship joins on non-unique columns, and this can be slower than a one-to-many join on large tables. A bridge adds a table that can be large if both sides have many members. Test on realistic data. The final chapter covers validation and timing.
Filter flow compared
The diagram shows how a selection on Customers reaches Transactions in the bridge design.
The first step and the last step work with the default single direction. The middle step runs against the arrow of the relationship from Accounts to AccountBridge, so it needs bidirectional filtering. You get that in one of two ways. You can set the relationship to both directions in the model, or you can write a measure that uses CROSSFILTER.
Trade-offs of bidirectional filtering
Setting the bridge relationship to both directions is the simplest fix, and it is where problems start.
- Ambiguity. If the model has other paths between the same tables, Power BI may refuse to set the direction, or it may choose a path you did not expect.
- Unexpected results. A bidirectional relationship lets slicers on one dimension filter another dimension. Slicers can start to hide each other's values.
- Performance. Filters travel further and the engine does more work.
A measure with CROSSFILTER limits this to the calculation that needs it:
Amount via Bridge =
CALCULATE (
SUM ( Transactions[Amount] ),
CROSSFILTER ( AccountBridge[AccountID], Accounts[AccountID], BOTH )
)The model keeps single-direction relationships, and only this measure uses both directions. The cost is that every measure which needs the path must include it.
A worked decision
Suppose a bank reports transaction amounts by customer. Accounts can be joint, so one account has several customers and one customer has several accounts. The data team gives you an AccountCustomer table with a row for each account and customer pair, and it contains some duplicate rows.
- True many-to-many? Yes. Joint accounts exist, and the duplicates in
AccountCustomerare only repeated rows, not extra relationships. - Does the link need its own data? Not yet. But the business may ask later to split a joint account by ownership share. That points to a bridge.
- Are dimensions available? Yes. The model has
CustomersandAccountswith unique IDs. - Who uses the model? Several analysts write their own measures. A visible bridge is safer than a pattern each analyst must remember.
The choice is a bridge table. You build it without duplicates:
AccountBridge =
DISTINCT (
SELECTCOLUMNS (
AccountCustomer,
"AccountID", AccountCustomer[AccountID],
"CustomerID", AccountCustomer[CustomerID]
)
)Then you connect Customers to the bridge and the bridge to Accounts, and set the direction as needed. If one report needs a different behaviour, you add a TREATAS measure for it:
Amount for Selected Customers =
CALCULATE (
SUM ( Transactions[Amount] ),
TREATAS ( VALUES ( AccountBridge[AccountID] ), Transactions[AccountID] )
)This measure takes the account IDs left visible in the bridge after a customer filter and applies them to Transactions[AccountID] directly. It does not need the Accounts relationship, so the middle step in the diagram is skipped.
When native many-to-many is the better choice
A bridge is not always the right answer. Native many-to-many is reasonable when all of these hold:
- You are joining two tables that have no natural dimension between them, for example two summary tables at different grains.
- The link has no attributes of its own.
- The model is small, or used by one author.
- You can check the totals and you know how they behave.
Avoid it when you expect to need weights, when the model is shared widely, or when a clean star schema is a requirement of the team.
When a DAX-only approach is the better choice
A TREATAS measure fits when the relationship is needed in only a few measures, or when making a permanent relationship would create ambiguity with others. It also fits when the link is temporary or comes from a disconnected table, such as a selection table. It fits poorly when many measures need the same link, because each one repeats the pattern.
Common mistakes
- Picking the option before checking the data. Duplicate keys that are errors get hidden by a many-to-many relationship instead of fixed.
- Setting both directions everywhere. This works in a demo and causes ambiguity in a larger model.
- Assuming totals will add up. With shared accounts, per-customer amounts add to more than the real total. The
Rows Checkmeasure from the validation chapter finds this:
Rows Check =
VAR GrandTotal = CALCULATE ( [Total Amount], ALL ( Customers ) )
VAR VisibleSum = SUMX ( VALUES ( Customers[CustomerID] ), [Amount via Bridge] )
RETURN VisibleSum - GrandTotalA result of zero means each account belongs to one customer in the current selection. Any other value is the amount counted more than once.
Summary of the decision
| If this is true | Prefer |
|---|---|
| Keys are duplicated by mistake | Fix the data, then use one-to-many |
| The link needs weights or dates | Bridge table |
| Many authors write measures | Bridge table |
| Quick link between two tables, no extra data | Native many-to-many |
| Only a few measures need the link | `TREATAS` measure |
| One measure needs both directions | `CROSSFILTER` in that measure |
Exercise
A retailer has a Products table and a Promotions table. One product can be in several promotions, and one promotion covers several products. Management wants each promotion's sales to be split by a "share of promotion" percentage for each product. Which approach do you choose, and why?
Show answer
A bridge table. The link needs its own data (the share percentage), and a native many-to-many relationship cannot store columns. Build a bridge of unique ProductID and PromotionID pairs with a Weight column, connect it to both dimensions, and multiply the sales by the weight in measures.
Exercise
A single report needs sales for the customers selected in a slicer, but you do not want to change the filter direction in the shared model. Name two DAX techniques that let one measure do this, and say which relationship step each one replaces.
Show answer
CROSSFILTER turns on bidirectional filtering between the bridge and Accounts for that one measure, so the Customer selection reaches Transactions through the existing Accounts relationship. TREATAS takes the AccountID values left visible in the bridge and applies them directly to Transactions[AccountID], so the Accounts relationship is skipped.