A
C
- CALCULATE
- CALCULATETABLE
- CALENDAR
- CALENDARAUTO
- CEILING
- CHISQ.DIST
- CHISQ.DIST.RT
- CHISQ.INV
- CHISQ.INV.RT
- CLOSINGBALANCEMONTH
- CLOSINGBALANCEQUARTER
- CLOSINGBALANCEYEAR
- COALESCE
- COLUMNSTATISTICS
- COMBIN
- COMBINA
- COMBINEVALUES
- CONCATENATE
- CONCATENATEX
- CONFIDENCE.NORM
- CONFIDENCE.T
- CONTAINS
- CONTAINSROW
- CONTAINSSTRING
- CONTAINSSTRINGEXACT
- CONVERT
- COS
- COSH
- COT
- COTH
- COUNT
- COUNTA
- COUNTAX
- COUNTBLANK
- COUNTROWS
- COUNTX
- COUPDAYBS
- COUPDAYS
- COUPDAYSNC
- COUPNCD
- COUPNUM
- COUPPCD
- CROSSFILTER
- CROSSJOIN
- CUMIPMT
- CUMPRINC
- CURRENCY
- CURRENTGROUP
- CUSTOMDATA
D
E
I
N
O
P
R
S
- SAMEPERIODLASTYEAR
- SAMPLE
- SEARCH
- SECOND
- SELECTCOLUMNS
- SELECTEDMEASURE
- SELECTEDMEASUREFORMATSTRING
- SELECTEDMEASURENAME
- SELECTEDVALUE
- SIGN
- SIN
- SINH
- SLN
- SQRT
- SQRTPI
- STARTOFMONTH
- STARTOFQUARTER
- STARTOFYEAR
- STDEVX.P
- STDEVX.S
- STDEV.P
- STDEV.S
- SUBSTITUTE
- SUBSTITUTEWITHINDEX
- SUM
- SUMMARIZE
- SUMMARIZECOLUMNS
- SUMX
- SWITCH
- SYD
T
U
In this article, we will explain in detail how to use the USERNAME function in Power BI, including its syntax, parameters, and examples.
Syntax
The syntax of the USERNAME function is straightforward. It only takes one optional parameter, which is the name of the session. Here is the syntax for using the USERNAME function in Power BI:
USERNAME([session_name])
The session_name parameter is optional. It specifies the name of the session you want to retrieve the username from. If you omit this parameter, the function will return the username of the current session.
Parameters
As mentioned earlier, the USERNAME function only takes one optional parameter, which is the session_name. Here is how to use the parameter:
USERNAME(“MySession”)
This will return the username of the session named "MySession". If you omit the parameter, the function will use the current session by default.
Examples
Here are some examples of how to use the USERNAME function in Power BI:
Example 1: Use USERNAME function to filter data by user
Suppose you have a sales dashboard that shows the revenue generated by each sales executive. You want to restrict the data to only show the revenue generated by the logged-in user. Here is how to achieve this:
1. Create a measure that uses the USERNAME function to retrieve the name of the current user:
Current User = USERNAME()
2. Create another measure that sums up the revenue generated by each sales executive:
Total Revenue = SUM(Sales[Revenue])
3. Create a new measure that filters the Total Revenue measure by the Current User measure:
My Revenue = CALCULATE([Total Revenue], Sales[Sales Executive] = [Current User])
This will filter the data to only show the revenue generated by the logged-in user.
Example 2: Use USERNAME function for auditing
Suppose you want to keep track of who made changes to a particular dataset. You can use the USERNAME function to record the name of the user who made the changes. Here is how to achieve this:
1. Create a new column in the dataset that uses the USERNAME function to retrieve the name of the current user:
User Name = USERNAME()
2. Whenever a user updates the dataset, the User Name column will automatically capture the name of the user who made the changes.
Example 3: Use USERNAME function for personalized dashboards
Suppose you want to create a personalized dashboard that shows different charts and visualizations based on the user's role. You can use the USERNAME function to determine the user's role and display the appropriate visualizations. Here is how to achieve this:
1. Create a measure that uses the USERNAME function to retrieve the name of the current user:
Current User = USERNAME()
2. Create a measure that uses the USERPRINCIPALNAME function to retrieve the user's email address:
User Email = USERPRINCIPALNAME()
3. Create a new table that maps the user's email address to their role:
User Roles:
User Email | Role
————————–
user1@example.com | Manager
user2@example.com | Sales Executive
user3@example.com | Analyst
4. Create a measure that retrieves the user's role based on their email address:
User Role = LOOKUPVALUE(‘User Roles'[Role], ‘User Roles'[User Email], [User Email])
5. Use the User Role measure to display the appropriate charts and visualizations based on the user's role.
The USERNAME function in Power BI is a powerful function that can help you identify the current user and use that information to create personalized dashboards, filter data, and keep track of changes. By understanding the syntax and parameters of this function, you can leverage it to improve your Power BI reports and dashboards.