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.
This expression has no parameters.
Let’s get started-
Load below sample dataset into Power BI desktop-
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.
Step-3: After that add one table visual into Report page with some columns.
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
Step-5: After that follow these steps-
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()
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.
Step-9: Enter user mail id > Click on Add button > Save.
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
Now login from user 1 account and checked it is working or not-
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.