USERNAME Function (DAX)

How does the USERNAME function (DAX) work?

The USERNAME function (DAX) returns the domain name and username from the credentials given to the system at connection time.

USERNAME Formula Syntax

USERNAME (
     
)

How do you use the USERNAME function?

The function is often used to customize the way queries or formula’s operate based on the user that is currently running a report or dashboard. It can also be used in driving member level security for data models – allowing a data model to be customized for each user logging into the application.

Related Blog Posts

Related Support Forum Posts

Power BI Report Builder – Find User Name From Power BI Cloud
Dynamic Row Level Security w/ Multiple Criteria
Row Level Security- Question

Considerations when using the USERNAME function

  • The function returns a text string of the user’s name
  • The function takes no inputs
  • If the logged in user for example was called “john.smith”, it would return a member with unique name [Security].[User].[John.Smith]. If this was used in the member security settings for a model in the admin settings, it could be used to filter all the rows in the Security table of model (as shown below), which in turn would secure the data for the entire model (via country).

Related Video Tutorials

Formula examples using the USERNAME function

=IF(CONTAINS(UsersTable,UsersTable[login], USERNAME()), “Allowed”, BLANK())

if( left(UserName(),4)==”0000″, sum([measure].[sales]), avg([measure].[sales]) )

NonEmpty( AllMembers([customers].[Country]) , (StrToMember([Security].[User],UserName())) )

Related Course Modules

Ultimate-Beginners-Guide-To-PowerBI
Center of Excellence

DOWNLOAD


Download our comprehensive DAX Formula Reference Guide as perfect companion as you learn how to use DAX formulas within Power BI.


Download DAX Formulas Reference Guide
Download DAX Formula Reference Guide
Membership