Difference between USERNAME() and USERPRINCIPALNAME() in Power BI Dax

In this Power BI DAX Tutorial, We will discuss what is the difference between USERNAME() and USERPRINCIPALNAME() in the Power BI DAX Function.

Also, we will see the syntax of USERNAME() and USERPRINCIPALNAME() Power BI functions. How to use USERNAME() and USERPRINCIPALNAME() in Power BI and what it returns in the Power BI Desktop and as well as Power BI Online Service.

USERNAME() Vs. USERPRINCIPALNAME()

The Power BI DAX USERNAME() function helps to return the user domain login with the form of (Domain\User) in the locality or your local system.

The Power BI DAX USERPRINCIPALNAME() function helps to return the user principal name with the form of (User’s login credential or Preeti@<tenant>.onmicrosoft.com) in the Power BI Online Service.

Syntax

Below represents the syntaxes of USERNAME() and USERPRINCIPALNAME() Function:

To apply the syntax functions, at first, you need to create a New measure and put the below formula into it.

USERNAME() Power BI Function Syntax

User Name = USERNAME()

Here,

  • User Name = Measure Name
  • USERNAME() = Function of the User name

USERPRINCIPALNAME() Power BI Function Syntax

User Principal Name = USERPRINCIPALNAME()

Here,

  • User Principal Name = Measure Name
  • USERPRINCIPALNAME = Function of the User Principal Name

What it Returns

When you will apply the USERNAME() and USERPRINCIPALNAME() DAX Function, then it returns the user domain login (Domain\User) in the Power BI Local Desktop.

But in the Power BI Online Service, both of the DAX Functions return the user name with the login credentials.

See also  How to create a relationship in power bi without unique values

In Power BI Desktop

At first, Create two New Measures and apply the USERNAME() and USERPRINCIPALNAME() function formulas in each of the formula bars.

Add a Table under the Visualizations section, then the output will return the Domain with the user name in locally as the below screenshot.

how to use power bi username functions

In Power BI Online Service

Publish the Power BI Report in your Local Desktop and Sign in your Power BI Online service account in the browser.

Open your Power BI Report, then you can see the user name with your login credentials as shown below.

difference between username and userprincipalname in dax

Also, you may like the below Power BI tutorials:

In this Power BI DAX Tutorial, We discussed what is the difference between USERNAME() and USERPRINCIPALNAME() in the Power BI DAX Function.

Also, we saw what are the syntaxes of both the functions, How you can use it and what it returns in the Power BI Desktop and as well as Power BI Online Service.

>