DAX Function Guide
USERNAME
Sam McKay
CEO & Founder
How does the USERNAME work?
USERNAME Formula Syntax
USERNAME (
)
How do you use the USERNAME?
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
Loading
Considerations when using the USERNAME?
- 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
Loading
Formula examples using the USERNAME
=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 Courses
Loading