Sub topic 7
Designing a security mapping table
A security mapping table stores who may see which rows. A dynamic role reads it and filters the model for the signed-in user. This chapter covers the table's shape, the relationships it needs, and the mistakes that expose data or return empty reports.
This chapter assumes you can build a star schema in Power BI Desktop, write simple DAX, and have already seen USERPRINCIPALNAME() in a role filter. It also assumes you know what a one-to-many relationship is.
Why a mapping table
A static role hard-codes values such as [Region] = "West". That needs one role per audience, and every change means editing the model and republishing it.
A mapping table moves that information into data. One role holds a single filter expression. Adding a person, or changing a person's region, is a row change in the source and a refresh, with no role edits.
The dynamic filter from the earlier chapter on dynamic RLS looks like this:
[Region] IN CALCULATETABLE (
VALUES ( Security[Region] ),
Security[UserEmail] = USERPRINCIPALNAME ()
)This expression is applied to the Region dimension table. It reads the Security table, keeps the rows for the current user, and returns the set of regions those rows list.
The shape of the table
The simplest design has one row per user and per allowed value.
| UserEmail | Region |
|---|---|
| [email protected] | West |
| [email protected] | Central |
| [email protected] | East |
| [email protected] | West |
Follow these rules:
- Store the sign-in name, not the display name. The value must match what
USERPRINCIPALNAME()returns, which is normally the user principal name (UPN) from Microsoft Entra ID. Use the same spelling as the account, for example[email protected]. - Use one row per user-and-value pair. Ana sees two regions, so she has two rows. Do not pack values into a comma-separated cell, because the filter compares whole values.
- Store the key that the dimension table uses. If
Regionhas a key column such asRegionID, map on the key, not on a label that might be renamed. - Keep the table narrow. It holds identities and keys, and nothing else.
You can check what the model sees for a signed-in user with a measure:
Current User = USERPRINCIPALNAME()Put it in a card while testing. If the card shows a value that differs from the text in UserEmail, the filter will return no rows for that person.
Where the table sits in the model
The mapping table does not need to connect to the rest of the model. In the pattern above, the role filter on Region calls CALCULATETABLE on Security directly. The Security table stays disconnected, and Region filters the fact table through its ordinary relationship.
This is the design most teams should start with. Its main benefit is that the security table never appears in report filters, and report authors cannot accidentally slice by it.
The alternative: a connected security table
Another pattern relates Security to the dimension and puts the filter on Security itself:
[UserEmail] = USERPRINCIPALNAME()The role filters Security to the current user's rows. That filter then travels through a relationship to the dimension, and from the dimension to the fact table. This only works if the filter direction runs from Security toward the data. Because Region is on the one side of its relationship with Sales, you need one-to-many from Security to Region as well. That requires Region values to be unique in Security, which they are not when several users share a region. A many-to-many relationship, or a bidirectional filter, is then needed.
Bidirectional filtering on a security path brings costs: slower queries, ambiguity between paths, and extra care when tables are added later. For these reasons, prefer the disconnected table with the IN CALCULATETABLE filter unless you have a specific need for the connected one.
| Aspect | Disconnected table | Connected table |
|---|---|---|
| Role filter | On the dimension, uses `CALCULATETABLE` | On `Security`, `[UserEmail] = USERPRINCIPALNAME()` |
| Relationship needed | None for `Security` | Security to dimension, often many-to-many or bidirectional |
| Visible to report authors | Can be hidden | Can be hidden, but sits in the filter path |
| Risk | Typing errors in the expression | Ambiguity and performance cost |
Filtering the fact table directly
Some models store the user in the fact table itself, such as a ManagerEmail column on Sales. Then no mapping table is needed:
[ManagerEmail] = USERPRINCIPALNAME()This is simple but has limits. Each fact row has exactly one owner, so a row cannot be shared with a second person, and an ownership change means rewriting fact data. Use a mapping table when access is many-to-many, when it changes often, or when the fact table is large and rarely rewritten.
Mapping on more than one dimension
Real rules often cover more than one attribute, for example region and product line. You have two options.
The first is to make a separate mapping table per dimension and apply a filter on each dimension in the same role. A role can hold one filter expression for every table. A user must satisfy all of them, so the filters combine with AND. Someone mapped to West and to Bikes sees only West rows for Bikes.
The second is a single mapping table with a combined key, for example a RegionProduct column, and a matching column on the fact table. This handles rules such as "West only for Bikes, East only for Parts", which separate tables cannot express because they would also allow West Parts. The cost is a combined key column in the fact table.
Giving everyone full access
Some users, such as executives, should see every region. Do not rely on an empty mapping, since a user with no rows gets no data. Choose one of these:
- List every region for that user in the table, one row each. This is explicit and easy to audit, but needs updating when a region is added.
- Create a separate role with no filter and assign it to those users. A user who has several roles gets the union of what they allow, so an unfiltered role grants full access.
- Place a marker value such as
ALLin the table and extend the filter to test for it.
The marker option looks like this:
VAR UserRows =
CALCULATETABLE (
VALUES ( Security[Region] ),
Security[UserEmail] = USERPRINCIPALNAME ()
)
RETURN
"ALL" IN UserRows
|| [Region] IN UserRowsIt works and keeps access in one place, but it adds logic to a security expression. Test it closely, because a typo in the marker silently denies access.
Maintaining the table
The mapping table is data, so it needs ownership.
- Source it from a governed location, such as a database table or a SharePoint list, with a named owner who approves changes.
- Refresh it on a schedule that matches how fast access must change. Revoking a user's row takes effect only after the next refresh of the semantic model.
- Remove rows when people leave. A former employee's account may be disabled in Entra ID, but stale rows can attach to a reused address.
- Trim and standardize text. A trailing space or a different letter case can break a match. Comparison in DAX with
=ignores case, but spaces still matter, so clean the column in Power Query. - Remove duplicates. Duplicate rows do not widen access, since the filter works on a set of values, but they make audits harder.
Common design mistakes
- Mapping on a display name. Names are not unique and are not what
USERPRINCIPALNAME()returns. - Misspelled region values. A value in
Securitywith no match in the dimension grants nothing, with no error. - Leaving the
Securitytable visible. Report authors can drag it into visuals and see who has access to what. Hide it from report view. - Assuming a user missing from the table sees nothing in every context. Within RLS they see nothing from the filtered dimension, but any table not touched by the role still returns all rows. A role limits only the tables that its filter reaches.
- Using the mapping table with a dimension that has no relationship to the fact table. The filter works on the dimension and stops there, so facts stay unfiltered.
Checking your work
Before you publish, run through this list.
- Add the
Current Usermeasure to a card and view the model as a role to confirm the identity string. - Confirm every
UserEmailvalue matches a real sign-in name exactly. - Confirm every key in
Securityexists in the dimension. - Confirm the dimension has a one-to-many relationship to the fact table, with the filter flowing from dimension to fact.
- View as each type of user: one region, several regions, full access, and a user absent from the table.
Exercise
A Security table has columns UserEmail and Region. Ben appears with the rows East and East (a duplicate), and Dana has no rows. The role on the Region dimension uses [Region] IN CALCULATETABLE ( VALUES ( Security[Region] ), Security[UserEmail] = USERPRINCIPALNAME () ). What does each of them see in a Sales visual, and does the duplicate row change Ben's access?
Show answer
Ben sees only East sales. The duplicate does not widen his access, because VALUES returns a set of distinct values. Dana sees no rows from Sales, since the filter on Region returns an empty set and that empty filter flows to the fact table. Her report appears empty rather than showing an error.
Exercise
Executives must see every region, and Region values are added from time to time. Name two ways to give them full access and one risk of each.
Show answer
First, create a separate unfiltered role and assign the executives to it. Roles combine as a union, so it grants all rows. The risk is that anyone added to that role also gets everything, so membership needs controls. Second, put an ALL marker in the mapping table and extend the filter to test for it. This keeps access in one place, but a typo in the marker silently denies access. Listing every region per executive also works, but it must be updated whenever a region is added.