Row-level security in Power BI, explained

What row-level security does in Power BI, static and dynamic roles, a security table with USERPRINCIPALNAME, who it applies to, and how to test it.

Short answer: row-level security (RLS) limits which rows of a semantic model a person can see. You define roles with DAX filters in Power BI Desktop, publish, and add people or groups to each role in the service. A dynamic role uses USERPRINCIPALNAME() and a security table, so one role serves everyone. RLS applies to people with the Viewer role on the workspace, or who see the report through an app or a share; workspace Admins, Members and Contributors see all rows.

One report for every region, each manager seeing only theirs, is the usual goal. The model does the filtering, so every visual, export and Analyze in Excel connection respects it.

Static or dynamic roles?

Static
  • a role per region, with a fixed filter like Region = "West"
  • simple, but one role per value
Dynamic
  • one role
  • a security table maps each sign-in to what it may see
Two ways to write a role

How does a dynamic role filter the facts?

  1. 1
    Sign-inanna@contoso.com
  2. 2
    Security tableAnna may see West and North
  3. 3
    Regionfiltered to West and North
  4. 4
    Salesonly those regions' rows reach every visual
One sign-in, filtered down to its rows

The security table has one row per person and region. Relate it to the Region dimension, and the role filters the security table only:

-- Role "By user", filter on the table UserRegion
UserRegion[Email] = USERPRINCIPALNAME ()

The filter flows from UserRegion to Region to Sales. For it to cross from UserRegion to Region, that relationship needs Apply security filter in both directions, or write the filter on Region with a lookup:

-- Role "By user", filter on the table Region
Region[RegionID] IN
    CALCULATETABLE ( VALUES ( UserRegion[RegionID] ), UserRegion[Email] = USERPRINCIPALNAME () )

How do you test it?

In Power BI Desktop, Modeling > View as shows the report as a role, and with Other user as a given email. In the service, Test as role on the semantic model's security page does the same with real sign-ins. Test a person with two regions and a person with none: someone with no row in the security table should see nothing, not everything.

What goes wrong?

  • Testing as a workspace member. Members see all rows. Test with a Viewer, or with View as.
  • Totals that leak. A measure that removes filters with ALL still respects RLS, but a "share of total" then means share of what the person may see. Decide which one the report means.
  • Email case and guests. USERPRINCIPALNAME() returns the sign-in as Entra has it; guest users can look different. Compare emails in lower case.

Where can you check this?

Where do you start?

The open course Row-level security that holds builds a role, one role for everyone, and the tests, in a model of your own.

Keep reading

More from the blog.

Every post

Next

Building this? Say hello.

A question about this post, a pattern you would build differently, or the next thing you want written out: Behnia reads every message.