Skip to main content

How to Get the Signed-In User in Power BI with USERPRINCIPALNAME

· 4 min read
Jagdish Kumawat
Founder @ Dewiride

USERPRINCIPALNAME returns the signed-in user's user principal name (UPN), the sign-in name that looks like an email address. It's what row-level security rules compare with a table of emails, so each person sees only their rows. Here's its general form and a measure that shows who is viewing a report.

Syntax​

General form
USERPRINCIPALNAME()

From Microsoft's USERPRINCIPALNAME function reference:

  • No parameters. The parentheses are still required.
  • The result is the userprincipalname at connection time: the user viewing the report.

Microsoft's row-level security article adds that in the Power BI service, username() and userprincipalname() will both return the user's User Principal Name (UPN). This looks similar to an email address.

The example is a measure on the Expenses table of a semantic model, shown on a card.

Step 1: Create the Measure​

Select the Expenses table and New measure (How to Create a Measure in Power BI in the Browser), and enter:

Expenses → Signed in as
Signed in as = USERPRINCIPALNAME()

The formula bar with Signed in as = USERPRINCIPALNAME()

Press Enter.

Step 2: Show It on a Card​

On a card (How to Add a Card to a Power BI Report), Signed in as shows the sign-in name of whoever is viewing the report, here the report's author:

A card with the label Signed in as and the value admin@example.com

Each viewer sees their own name on the same card.

Use It in Row-Level Security​

A role rule that keeps a person's own rows compares an email column with the function (How to Add Row-Level Security Roles in Power BI in the Browser):

Role rule on Expenses
[SubmitterEmail] = USERPRINCIPALNAME()

A Signed in as card is a quick way to check that the emails in your data match what the function returns.

Common Mistakes​

MistakeWhat happensDo this instead
Leaving out the parenthesesAn errorUSERPRINCIPALNAME()
Comparing it with display namesNothing matchesCompare it with emails or UPNs
Assuming the UPN is always the emailPeople whose UPN differs from their email see nothingCheck a few users with the card

Troubleshooting​

SymptomLikely causeFix
A role shows no rows for someoneTheir UPN isn't in the email columnCompare the card's value with the data
The card shows your own name while testing a roleTest as role evaluates the function as youTest as a specific person instead (How to Test Row-Level Security in Power BI)
Guests see nothingMicrosoft's article says a guest's UPN can take a different formCheck what the card shows for a guest

FAQ​

What's the difference from USERNAME?​

In the Power BI service, both return the UPN; in Power BI Desktop, USERNAME returns DOMAIN\User, as the row-level security article describes.

Does every viewer see their own name?​

Yes. The function is worked out for whoever has the report open, so the same card shows a different name to each viewer.

Conclusion​

USERPRINCIPALNAME() returns the viewer's user principal name. The example's Signed in as card showed the author's sign-in name, and the same function filters rows in a role rule.

Additional Resources​