Sub topic 7
Designing a security mapping table
This chapter assumes you can build a star schema in Power BI Desktop, write simple DAX filters, and create roles. It also assumes you know that a role filter on a dimension table flows to related fact tables. Here you design the table that lets one dynamic role serve every user.
Why a mapping table
A filter like [ManagerEmail] = USERPRINCIPALNAME() works only when the table you filter has a column of user names. Most dimension tables do not. A user may also need several regions, and one region may need several users. A separate security mapping table stores those assignments in one place. You then maintain access by editing rows, not by editing roles.
Shape of the table
Keep the table narrow. Each row grants one user access to one value.
| UserEmail | Region |
|---|---|
| [email protected] | West |
| [email protected] | East |
| [email protected] | West |
Follow these design rules:
- Store one grant per row. Do not put several regions in one cell.
- Use the exact sign-in name that
USERPRINCIPALNAME()returns, usually the user's email-style UPN. Case differences do not matter in DAX string comparison, but different spellings do. - Grant on the key of a dimension, such as Region, not on a fact table column.
- Do not repeat descriptive columns. The table holds only the user and the key.
Where it sits in the model
Do not create a relationship from the Security table to the Region table for this pattern. Instead, the role filter on Region looks up the user's rows in Security. This keeps the Security table from filtering anything in reports, and the role does the work.
[Region] IN CALCULATETABLE (
VALUES ( Security[Region] ),
Security[UserEmail] = USERPRINCIPALNAME ()
)The expression runs inside the role, on the Region table. CALCULATETABLE filters Security to the signed-in user's rows. VALUES returns their regions. IN keeps only Region rows in that list. The filter then travels from Region through its one-to-many relationship to the fact table.
Check the identity first
Before you trust the mapping, confirm what the model sees for the user. Add this measure and show it in a card while testing a role.
Current User = USERPRINCIPALNAME()In Power BI Desktop, USERPRINCIPALNAME() often returns a local-style name, not the UPN you will see in the service. Compare the value you see in the service with the value in your table, and fix the table if they differ.
Common design mistakes
- Bidirectional filtering added to "make it work." A two-way relationship between Security and a dimension can let filters flow back and expose or hide rows in ways you did not intend. Prefer the lookup expression above.
- Mismatched names. An alias or a typo in
UserEmailproduces an empty report for that user, not an error. - Missing users. A user assigned to the role with no row in Security sees no data. This is safe, but it looks like a bug.
- Granting on the wrong grain. If Security lists Region but your dimension is at City level, relate through a table at the Region grain, or grant at City.
Maintaining the table
Load the mapping from a source the access owner controls, such as a SharePoint list, a database table, or a spreadsheet. Refreshing the semantic model then updates who sees what. Role membership in the service does not change.
Exercise
Ana should see West and East, and Ben only West. Describe the rows in the Security table, and explain why a user assigned to the role but absent from the table sees an empty report.
Show answer
Three rows: ([email protected], West), ([email protected], East), ([email protected], West). The role filter keeps only Region rows whose value appears in the user's Security rows. A user with no rows gets an empty list, so no Region rows pass the filter and no fact rows are returned.
Exercise
Why is it risky to make the relationship between Security and Region bidirectional to avoid writing the CALCULATETABLE expression?
Show answer
Filters can then flow from Region back to Security, which can change what other filters and role logic see, and it can expose or hide rows unexpectedly. The lookup expression keeps the filter direction one-way and explicit.