Sub topic 8
Testing roles in Desktop and the service
This chapter assumes you have built at least one static or dynamic role, understand how a role filter travels through relationships, and can open a semantic model in Power BI Desktop and in the Power BI service. Testing comes before assignment. A role that looks correct in the editor can still return nothing, or too much.
Why test as the user
A role is only a set of DAX filters. You can't judge it by reading the expression, because the result depends on the data, the relationships, and the identity the model sees. Testing runs the report as if you were a member of the role and shows what that member would get.
Two tools do this:
- View as in Power BI Desktop.
- Test as role in the Power BI service.
Testing in Power BI Desktop
Desktop doesn't know who your test users are, so you choose the role yourself.
- On the Modeling tab, select View as.
- Tick the role you want to test. Tick several to see how they combine.
- For a dynamic role, tick Other user and type the sign-in name to impersonate, for example
[email protected]. - Select OK. A yellow banner shows which role is active.
- Select Stop viewing to return to the full model.
For a static role such as [Region] = "West", ticking the role is enough. For a dynamic role, Other user matters. Without it, USERPRINCIPALNAME() returns your own account, and you test the wrong identity.
A small measure confirms which identity the model sees:
Current User = USERPRINCIPALNAME()Add it to a card visual. While viewing as [email protected], the card should show that address.
Testing in the Power BI service
The service tests the published model, with its real relationships and data.
- Open the workspace and find the semantic model.
- Select More options (...), then Security.
- Select the role, then choose Test as role.
- Optionally enter a user in Now viewing as to test a dynamic role as someone specific.
The report opens with the role's filters applied. Use the Now viewing as control to switch between roles and users without leaving the page.
What to check
Run the same checks for every role.
| Check | Expected result |
|---|---|
| Row counts on a fact table | Only rows allowed by the role |
| Totals on a card | Lower than the unrestricted total |
| A user with no mapping row | Empty visuals, not all data |
| `Current User` measure | The impersonated sign-in name |
| A dimension not covered by the role | Unchanged unless a relationship carries the filter |
Compare against a known answer. For example, if the West region has 1,200 orders in the unrestricted model, a West role should show 1,200.
Diagram: the testing loop
Common testing mistakes
- Testing as yourself. If you own the model, you see all rows. Always use a role or Other user.
- Forgetting the identity for dynamic roles. The name must match the value in the security table exactly, including case in your data source and any domain differences.
- Trusting Desktop only. Desktop tests the model. The service tests the published copy, including identity as Entra ID reports it.
- Not testing the negative case. Try a user who should see nothing and confirm the report is empty.
Exercise
You built a dynamic role with [ManagerEmail] = USERPRINCIPALNAME(). In Desktop you tick the role under View as and every visual is empty. What did you most likely forget, and how do you fix it?
Show answer
You didn't tick Other user and enter a sign-in name. The model used your own account, which has no matching rows in [ManagerEmail]. Open View as again, tick the role, tick Other user, and enter an address that exists in the data, such as [email protected]. A card with USERPRINCIPALNAME() should then show that address.
Exercise
A published role works in Desktop, but a colleague who has the Contributor workspace role sees all rows. Is the role broken?
Show answer
No. Contributors, Members, and Admins bypass RLS in the workspace. Give the colleague the Viewer role, or share the content another way, and then assign them to the RLS role.