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 one card visual into report and drag measure over it. Now you can see here at desktop level it returns the domain with PC name.
Step-3: After that add one table visual into Report page with some columns.
Step-4: Suppose user want to see only their sales data, so for that you have to create a role to using USERPRINCIPALNAME() DAX.
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 admin or Author of report you will see all data when you opens the report, so in that case if you want to see only your sales data follow these steps-
Click on ellipse icon > Test role as
Now login from user 1 account and checked it is working or not-
So you can see in above screen shot it is showing only logged-In user data.
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.