Stop 14 · Security, Performance & GovernanceTopics · 2/9

Dynamic RLS with USERPRINCIPALNAME

Part of the Power BI Roadmap

In short

Fifty sales reps means fifty static roles, and a new joiner means a model change. Dynamic RLS uses one role and a mapping table, so the signed-in user automatically sees only their own rows.

Dynamic RLS uses one role whose filter compares a user mapping table to USERPRINCIPALNAME(), the signed-in user's email, so each person automatically sees only their own rows.

The jaadu at a hotel reception desk checks a long guest register and hands each guest a key card that opens only their own room door.

Think of it like this

The hotel key card

A hotel doesn't print a separate door for every guest. Every guest gets the same kind of card, and the reception list decides which room it opens. In dynamic RLS, USERPRINCIPALNAME() is the card and your mapping table is the reception list.

Watch it happen

Sneha opens the report

Sneha
Power BI
UserRegion table
Sales visuals

Sign in

1/4Sneha signs in as sneha.iyer@retailco.in and opens the Sales report.

The big ideas

What you need to know

A mapping table

A table like UserRegion with one row per user and region they may see. It can come from HR data or a maintained Excel file.

USERPRINCIPALNAME()

Returns the signed-in user's UPN, usually their work email, in the Service. Compare it to the Email column.

Relationships do the rest

UserRegion (many side) relates to Region. Set that relationship to filter in both directions and tick Apply security filter in both directions, so the filter reaches Sales.

One role for all

Add everyone, ideally one big group, to the single role. Access changes are just edits to the mapping table.

How it works

Building dynamic RLS

  1. 1

    Load the mapping table

    Import UserRegion with Email and Region columns, using lower-case, trimmed emails.

  2. 2

    Relate it

    Connect UserRegion[Region] to Region[Region], set cross filter direction to Both and tick Apply security filter in both directions.

  3. 3

    Create one role

    Filter UserRegion with [Email] = USERPRINCIPALNAME().

  4. 4

    Test

    In Desktop use View as with Other user and type a colleague's email, together with the role.

  5. 5

    Assign and hide

    Publish, add a group to the role, and hide the UserRegion table from report view.

See it in code

Walk through the code

dax
1-- UserRegion table2-- Email                     | Region3-- rakesh.verma@retailco.in  | North4-- sneha.iyer@retailco.in    | South5-- sneha.iyer@retailco.in    | West6 7-- Role: Region Access   (table: UserRegion)8[Email] = USERPRINCIPALNAME ()9 10-- Debug measure to check who Power BI thinks you are11Who Am I = USERPRINCIPALNAME ()

1/3Sneha has two rows, so she will see two regions.

One role, one line of DAX. The mapping table decides who sees what.

Save yourself the pain

Common mistakes

Oops

Matching on display names like 'Sneha Iyer'.

Do this instead

Match on the UPN. Names change and repeat. If UPN and email differ in your company, store the UPN.

Oops

Testing only in Desktop and assuming the Service will behave the same.

Do this instead

Always test as a real Viewer, or with Test as role and a specific user in the Service.

Oops

Leaving the UserRegion to Region relationship single-direction and seeing every row.

Do this instead

Filters flow from the one side to the many side by default. Use both directions with the security option, or put the filter on Region instead: [Region] IN CALCULATETABLE ( VALUES ( UserRegion[Region] ), UserRegion[Email] = USERPRINCIPALNAME () ).

Your mission

One role for the whole team

~35 min

Quick check

A new rep joins and needs to see the East region. With dynamic RLS, what do you change?

Go deeper

  1. 1Build a small table mapping manager emails to regions.
  2. 2Write the role filter [Email] = USERPRINCIPALNAME() on that table.
  3. 3Test it with View as and a typed-in email address.

More topics at this stop

Stuck on this topic? Ask an Insider

Get 1:1 guidance from people who've walked this exact path — on the InsideEdge app.

Download
InsideEdge