username() and userprincipalname() in Power BI

In this Power BI DAX Tutorial, we’ll explore the difference between USERNAME() and USERPRINCIPALNAME() in Power BI DAX functions.

We’ll also cover the syntax of these functions, how to use them in Power BI, and what they return in both Power BI Desktop and the Power BI service.

What is a username in Power BI?

In Power BI, the DAX function USERNAME returns the user’s domain login in the format (Domain\User) based on the locality or your local system.

When you use the USERNAME function in Power BI Service, it returns the current user’s login credentials in the format (e.g., Bijay@<tenant>.onmicrosoft.com).

Syntax:

USERNAME()

USERNAME function in Power BI Desktop

Now we see what the username function is returning in Power BI Desktop.

1. Open the Power BI Desktop. As you can see, we can’t use any DAX function without data.

username and userprincipalname in power bi

2. Under the Home tab, click “Enter data“. Then, in the “Create Table” window, click the “Load” button.

difference between username and userprincipalname in power bi

3. Under the Home tab, click New measure.

dax username vs userprincipalname

4. In the formula bar, put the below expression.

User Name = USERNAME()
power bi username vs userprincipalname

5. Under the Home tab, select Visual gallery, and select the Slicer visual icon.

username vs userprincipalname power bi

6. Using the +Add data option, add the User Name into the Field.

username() vs userprincipalname()

7. The output will return the Domain with the user name locally, as shown in the screenshot below.

userprincipalname power bi

USERNAME function in Power BI Service

When we publish the above report in the Power BI Service, it will return the current user’s login credentials.

dax username vs userprincipalname

What is a userprincipalname in Power BI?

In Power BI, the DAX function USERPRINCIPALNAME returns the user’s domain login in the format (Domain\User) based on the locality or your local system.

power bi userprincipalname

When you use the USERPRINCIPALNAME function in Power BI Service, it returns the current user’s login credentials in the format (e.g., Bijay@<tenant>.onmicrosoft.com).

userprincipalname in power bi

Syntax:

USERPRINCIPALNAME ()

Now we know that In Power BI Desktop (where reports are built), both functions display the format ‘work area and name’ (DOMAIN\username). In Power BI Service (where reports are viewed), both functions return the email address format (username@domain.com).

In this Power BI tutorial, we explored the difference between the USERNAME() and USERPRINCIPALNAME() functions. We covered their syntax, usage in Power BI, and what they return in both Power BI Desktop and the online service.

You may also like the following Power BI tutorials:

>