Home » DAX » DAX USERPRINCIPALNAME – Use in RLS

DAX USERPRINCIPALNAME – Use in RLS

DAX UPN

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 Email
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 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.

UPN

UPN



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

Dataset example

Dataset example

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

Manage Role

Manage Role



Step-5: After that follow these steps-

Manage Role

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

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

Power BI service dataset

Step-9: Enter user mail id > Click on Add button > Save

Roles in Power BI Service

Roles in Power BI Service

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

Test role in Power BI service

Test role in Power BI service

Now login from user 1 account and checked it is working or not-

UPN in Power BI service

UPN in Power BI service

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.



Leave a Reply