DAX USERPRINCIPALNAME function returns the user name of currently logged user.
This DAX function is use in RLS for authorization, using this user only can see their own data.
It returns different result- In Power BI desktop it returns name of PC(domain\user) and in Power BI service returns the login email of currently logged user.
Syntax:
USERPRINCIPALNAME()
Parameter:
This expression has no parameters.
Let’s get started-
Load below sample dataset into Power BI desktop-
Table: Products
Product | Sales | Name | |
Bike | 120000 | User1 | user1@powerbitutorials.onmicrosoft.com |
AC | 100000 | Jhon | jhon@powerbitutorials.onmicrosoft.com |
Cycle | 20000 | User1 | user1@powerbitutorials.onmicrosoft.com |
Fan | 10000 | User1 | user1@powerbitutorials.onmicrosoft.com |
Lights | 4000 | Mark | mark@powerbitutorials.onmicrosoft.com |
Bottle | 3000 | User1 | user1@powerbitutorials.onmicrosoft.com |
Now follow these steps-
Step-1: Create a measure for UPN.
UPN = USERPRINCIPALNAME()
Step-2: Add a card visual into the report and place the measure on it. You will notice that at the desktop level, it presents the domain along with the PC name.

UPN
Step-3: After that add one table visual into Report page with some columns.

Dataset example
Step-4: Suppose a user wants to view only their sales data. To achieve this, you need to create a role using the DAX function USERPRINCIPALNAME().
Go to Modeling Tab >Manage roles > Click on create

Manage Role
Step-5: After that follow these steps-

Manage Role
Step-6: Now it will filter table data based on email id of user, and USERPRINCIPALNAME() DAX returns the logged user id in Power BI service.
[Email] = USERPRINCIPALNAME()

UPN DAX function in Mange roles
Step-7: Publish report into Power BI service.
Step-8: After publish you have to create a role for users. So in dataset we have one user with name User 1, so we will create role for that user.
Find your dataset in Power BI service and click on ellipse icon > Security.

Power BI service dataset
Step-9: Enter user mail id > Click on Add button > Save.

Roles in Power BI Service
How to check roles are working or not?
If you are an admin or the author of the report, you will have access to all data when you open the report. However, if you wish to view only your own sales data in such cases, follow these steps:
Click on ellipse icon > Test role as

Test role in Power BI service
Now login from user 1 account and checked it is working or not-

UPN in Power BI service
As you can observe in the screenshot above, it displays exclusively the data associated with the logged-in user.
Hope you enjoyed the post. Your valuable feedback, question, or comments about this post are always welcome or you can leave us message on our contact form , we will revert to you asap.