Sub topic 4
How role filters travel through relationships
This chapter assumes you can build a star schema in Power BI Desktop. It also assumes you have created a role with a DAX table filter expression, as covered in the earlier chapters on roles and static roles. Here you will learn which tables a role filter reaches, which it does not, and how to set relationships so the filter protects the data you intend.
A role filter is a filter on one table
A role holds one DAX expression per table. Each expression returns TRUE or FALSE for every row of that table. Rows that return FALSE are hidden from members of the role. Nothing else in the role definition mentions any other table.
Consider a role on the Region dimension with this expression:
[Region] = "West"The role does not say anything about Sales. The sales rows disappear for West-only users because of the relationship between Region and Sales. A relationship carries filters from one table to another, and the security filter uses the same path. If the relationship is missing, inactive, or points the wrong way, the filter does not arrive. The report then shows data the user should not see.
The default direction: one side to many side
In a star schema, each dimension table has a one-to-many relationship with the fact table. The filter direction is single, from the "one" side (the dimension) to the "many" side (the fact table). A filter placed on the dimension passes through to the fact rows. A filter placed on the fact table does not pass back to the dimension.
The block above is only a placeholder to avoid confusion. The real diagram follows.
Follow what a West-only user experiences:
- The
Regiontable contains only the West row. - The
Salestable contains only rows whoseRegionKeymatches a visibleRegionrow. ProductandDatekeep all of their rows, because no role filter touches them andSalesdoes not filter them back.
The third point has a visible side effect. A product slicer still lists every product, including products the user never bought in the West. Those products simply show blank values. The user sees product names but not the sales data behind them. If the product names themselves are sensitive, you need a role filter on Product too.
Putting the filter on the fact table
You can write a role filter directly on a fact table. It works for that table, but it does not travel to the dimensions.
[RegionKey] = 3With this expression on Sales, a user sees only the sales rows with RegionKey 3. The Region table still lists all regions, because the filter flows from dimension to fact, not the other way. Slicers on Region therefore show every region name, with blanks for all but region 3. Filtering the dimension is usually better. The filter is readable, it hides the dimension members, and it reaches every fact table related to that dimension.
| Where the filter is placed | Fact table rows | Dimension members shown |
|---|---|---|
| On the dimension (`Region`) | Filtered through the relationship | Only the allowed members |
| On the fact table (`Sales`) | Filtered directly | All members, most with blank values |
| On an unrelated table | Unaffected | Unaffected |
One dimension, many fact tables
A dimension can relate to several fact tables, such as Sales and Budget. One role filter on Region then secures both facts at once, as long as each fact table has an active relationship to Region. This is a strong reason to filter dimensions and not facts. A filter on Sales alone would leave Budget fully visible.
Check this whenever you add a new fact table. A new table without a relationship to the secured dimension is not protected by the role, and nothing warns you.
Seeing the filter at work
You can check what a role lets through with a few simple measures. Add them to a test report, then use View as (covered in the testing chapter) to see the numbers change.
Sales Rows = COUNTROWS ( Sales )Region Rows = COUNTROWS ( Region )Current User = USERPRINCIPALNAME()With the West role active, Region Rows returns 1 and Sales Rows returns only the West sales count. If Sales Rows still shows the full table, the filter is not reaching the fact table, so inspect the relationship.
Bidirectional relationships and security filters
Dynamic RLS often needs a filter to travel against the normal direction. Suppose the Security mapping table holds one row per user and region, and you filter Security by the current user. The Security table is on the "many" side of its relationship to Region. A filter on Security would not flow up to Region and then down to Sales.
Power BI lets you change this per relationship. In Manage relationships, edit the relationship and set the cross-filter direction to Both. Then select Apply security filter in both directions. That second checkbox is the important one. Without it, the relationship is bidirectional for normal report filtering, but role filters still move only in the single, one-to-many direction.
The second checkbox appears only when the cross-filter direction is Both. It also applies only to the relationship you edit, so you must set it on each relationship that needs it.
You do not always need this setting. In the fourth code example from the plan, the role filter sits on Region itself and uses CALCULATETABLE to look up the allowed regions in Security:
[Region] IN CALCULATETABLE (
VALUES ( Security[Region] ),
Security[UserEmail] = USERPRINCIPALNAME ()
)Here the expression reads Security through DAX, so it does not rely on a relationship to carry the filter. The filter is on Region, and the normal one-to-many relationship carries it to Sales. This pattern avoids bidirectional relationships, which are harder to reason about and can create ambiguous filter paths. The security table chapter returns to the trade-offs between the two designs.
Relationship properties that break propagation
A filter travels only along relationships that are active and that support the direction needed. These cases stop or change propagation:
- Inactive relationships. A relationship drawn as a dashed line is inactive, and a role filter does not travel along it. If a fact table joins to a dimension through an inactive relationship, that fact table stays unfiltered by that dimension. Make the relationship active, or filter the fact table directly.
- Missing relationships. Two tables with matching column names but no relationship are unrelated. Power BI does not match them by name.
- Many-to-many relationships. Filters can pass through them, but the results depend on the filter direction and on duplicate keys. Test them with a real user before you trust them.
- Role filters on both sides. If you filter both a dimension and the fact table, rows must satisfy both. The two filters combine, and the result is the intersection of the two sets of rows.
- Key columns with blanks. A fact row whose key does not match any dimension row is attached to a blank member. A filter on the dimension hides that blank member, so those rows disappear for filtered users. They may still appear for unfiltered users, which makes totals differ between users.
A worked example
You have three tables: Region (one row per region), Product, and Sales. Both dimensions have a single-direction, one-to-many relationship to Sales. You create a role named West Managers with this filter on Region:
[Region] = "West"Run through what each table looks like to a member of the role:
| Table | Rows visible | Reason |
|---|---|---|
| `Region` | West only | The role filter applies here directly |
| `Sales` | West sales only | The filter flows from `Region` to `Sales` |
| `Product` | All products | No filter reaches `Product`, since `Sales` does not filter it back |
Now suppose a colleague changes the Region to Sales relationship to inactive so a time-intelligence measure can use another path. The West role keeps its filter on Region, but Sales is no longer filtered by it. Every West user can now see all sales. Because the DAX of the role has not changed, nothing flags the problem. This is why you should retest every role after any change to the relationships.
A checklist for each role
- Name the table where the filter is written, and confirm it is the dimension, not a fact table, unless you intend otherwise.
- List every fact table that must be secured. Confirm each has an active relationship to that dimension.
- Confirm the relationship direction carries the filter from the filtered table to the data you want to hide.
- If you rely on a bidirectional relationship, confirm that Apply security filter in both directions is on for it.
- Decide whether dimension members, such as product names, are sensitive. If so, filter those dimensions too.
- Test with View as after every relationship change.
Exercise
A model has a Region dimension and a Sales fact table, joined by an active, single-direction, one-to-many relationship from Region to Sales. A role has the filter [RegionKey] = 3 on the Sales table only. A member of the role opens a report with a slicer on Region[Region]. What do the slicer and the sales total show, and how would you change the role so the slicer shows only the allowed region?
Show answer
The sales total includes only rows with RegionKey 3, because the filter is applied directly to Sales. The slicer still lists every region, because a filter on the fact table does not travel back to the dimension, and most regions show blank values. To fix it, remove the filter from Sales and put a filter on Region, such as [RegionKey] = 3. The one-to-many relationship then filters Sales as well, and the slicer lists only the allowed region.
Exercise
You set a relationship between Security (many side) and Region (one side) to cross-filter direction Both, and your dynamic role filters Security by USERPRINCIPALNAME(). In testing, users still see every region. What setting did you probably miss?
Show answer
You probably did not select "Apply security filter in both directions" on that relationship. Without it, role filters still follow only the single one-to-many direction, so the filter on Security does not reach Region or Sales.