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
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
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
To access our comprehensive DAX formula reference guide just insert your email address below. The resource will download immediately and we’ll also email it to you.