Returns the user name of the currently logged in user.
- Returned Output: Text
- Library: PQL \ Common \ Identity
- Version: 2018.00.000
- Can be combined with and other PQL function throughout the application.
- It CANNOT be used with MDX or VBA functions. But it can be used on MDX-based content in other parts of the application.
- The function returns a text string of the user's name
- The function takes no inputs
- 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.
Different Function types
- This function is like the MDX username function.
- The other "identity" functions can be used to secure and customize the analytics experience. If using an Active Directory as the authentication provider, the UserAdAccount function may provide similar functionality to the UserName function - depending on deployment scenarios. In other scenarios, the UserPrincipalName might be more appropriate (AD, SAML etc).
This example shows how to use the Username function to create a member object from a table called "security", on a column called "user".
If the logged in user 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).
So if the security table showed that John.Smith matched up with USA, then this function would limit the entire data model to only show USA data.
An alternative to the above approach, would be to set security on the country table directly, using a non-empty function and the following use of the username method.
NonEmpty( AllMembers([customers].[Country]) , (StrToMember([Security].[User],UserName())) )
In this more simplistic example, the username can be used to drive different logical formulas.
if( left(UserName(),4)=="0000", sum([measure].[sales]), avg([measure].[sales]) )
The above formula looks at the first 4 characters of the username using the Left function. If its starts with "0000", then the mathematical operation sums sales. Otherwise, it averages sales.