Microsoft Fabric Updates Blog

Using Username() in DAX with Row-Level Security

The trick to getting the DAX function Username() to return the user’s User Principal Name (UPN) in Power BI is to configure Row-Level Security (RLS) on the dataset within the Power BI service. If you haven’t enabled RLS, you may see some odd results.

Last week I posted a video about using Row-Level security in Power BI, and in the comments of the video I received a question regarding how to use Username() within a DAX expression.

image

Brian indicated he couldn’t find any examples of how to dynamically filter based on a username in DAX, even though he was told that it could be done.

To validate that Username() does indeed work, I added a DAX measure to my model:

User = username()

Within Power BI Desktop, this returned my Windows account — GUYINACUBE\asaxton.

image

However, when I published the Power BI Desktop model to the Power BI service, I saw a GUID returned as the value.

image

This is because in order for Username() to return a value, RLS needs to be enabled on the model. So, I created a role (any role will work) on the model for another user. After that was done, Username() returned the UPN of the user using the report. Note that you may need to refresh the report page to see the result.

image

I can then switch to a different user, and see their UPN.

image

Now you can go and make use of the Username() function within DAX calculations to further explore data.

Here is the RLS video that I referenced above. It doesn’t specifically show the use of Username(), but it is a good overview of RLS in general.

 

Adam W. Saxton | Microsoft Business Intelligence
@GuyInACube | YouTube | Facebook.com/guyinacube

Related blog posts

Using Username() in DAX with Row-Level Security

October 9, 2023 by Kay Unkroth

We have some very exciting news to share with you today! We are thrilled to announce that we have just launched the public preview of Direct Lake mode for Power BI datasets in Fabric! Fabric is taking a bold bet on open data formats in OneLake.

January 23, 2023 by Kay Unkroth

Thanks to the latest backup and restore improvements, you can now restore a backup file even when the dataset size is near the Power BI Premium SKU limitation. You no longer need to be concerned that dataset size limits impact restorability. When restoring a dataset with the /forceRestore option, Power BI will try its best to perform the restore operation even when the available memory is limited.