USERNAME Function in Tableau

What is Username function in Tableau

The USERNAME function in Tableau is a built-in function that returns the name of the current user who is logged in to Tableau Server or Tableau Desktop. Tableau USERNAME function can be useful when you want to create a dynamic report or visualization that is customized for each user. For example, you could use the Tableau USERNAME() function in a calculated field to create a filter that only shows data relevant to the currently logged in user.

The syntax for using the USERNAME() function is simple. You can insert the function into a calculated field or into a worksheet filter, like this:

USERNAME()

When you use this function in a calculated field, it will return the name of the current user as a string. You can then use this value in other calculations, filters, or other parts of your analysis as needed.

Key Features of USERNAME Function

The USERNAME() function in Tableau has several key features that make it a powerful tool for creating dynamic reports and visualizations:

  • Returns the current user name: The main function of USERNAME() is to return the name of the current user who is logged in to Tableau Server or Tableau Desktop.
  • Provides a dynamic value: Because the USERNAME() function returns the current user name, it can be used in calculated fields, filters, and other parts of your analysis to create dynamic, user-specific reports and visualizations.
  • Easy to use: The syntax for using the USERNAME() function is simple, so it’s easy to incorporate into your analysis.
  • Works with Tableau Server and Desktop: The USERNAME() function works with both Tableau Server and Tableau Desktop, so you can use it in a wide range of Tableau environments.
  • Enhances security: You can use the USERNAME() function to enhance the security of your reports and visualizations by restricting access to data based on the current user’s permissions or role.

Lets understand more with 3 useful examples of using the Tableau USERNAME function in Tableau, along with their syntax:

Example#1: Tableau user filter and Row Level security

Lets take example how you can create a filter that only shows data relevant to the currently logged in user. This is useful when you want to show few filters in the dashboard or row level security only for the management and all relevant filters to others analyst.

In this case you can use Tableau USERNAME() function in Filter Formula area where you can mentioned user names and required filters and filters members.

Syntex for this is

USERNAME() = [User Name]  //[User Name] is the name of users like "Deepak", "Robert" etc

In below example we want to apply filter restriction to one users for region = “Europe”

USERNAME()= "deepak" AND [Region] = "Europe"

The output will be look like as shown below image,

Output of Username function in Tableau applied in filter

In below image Deepak user can only see filter option for region = “Europe” only.

you can also use OR condition to put multiple user name also like

( USERNAME()= "Deepak" OR USERNAME()= "Mahesh" OR USERNAME()= "Robert" ) AND ([Region] = "Europe")

The first question come in your mind where you need to put formula in filter option, then follow below steps

  • Right click on filter and click on Edit filter
  • You will see the Filter edit window then click on Condition tab and enter the formula as shown below image
Username function in Tableau applied in filter as formula

This example creates a filter that only shows data where the value in the “User Name” field matches the current user’s name, as returned by the USERNAME() function. This can be useful for creating a user-specific view in your dashboard.

Example#2: Welcome message for current user in tableau dashboard

Next example is the simple example to displaying a welcome message that greets the current user by name.

Syntax:

"Welcome, " + USERNAME() + "!"

This example creates a calculated field that displays a welcome message to the current user, using the USERNAME() function in Tableau to insert the user’s name into the message.

This can be a useful way to personalize your Tableau reports and make them more engaging for users. like user name with displaying logged in date and time, User department and current organization to make user more personalize way to give user interactive view.

Example#3: User filter in calculated field using Tableau USERNAME function

This example is more useful, if you want to create a dynamic view that changes based on the current user’s permissions. You need to create calculated filed which display data/view for specific users based on his/her requirement of data to analyse in the dashboard.

Name of calculated filed will be UserFilter

IF USERNAME() = "admin" THEN [Full View] ELSE [Limited View] END

Ans also created two more calculated filed

  • Full View = [Region]
  • Limited View = [Country]
calculated Filed created for Username function

The output will be as shown below image

If user is “admin”, it will show Region fields

Region output for dynamic view

If user is not a “admin”, it will show Country fields

Country output for dynamic view

This example creates a calculated field that displays a different view of the data based on the current user’s permissions.

If the current user is an administrator (“admin”), the field will display a Region view of the data; otherwise, it will display a limited view by Country. This can be a useful way to create a more secure, role-based view of your Tableau dashboard.

Conclusion

Overall, the USERNAME() function is a versatile function that can be used to create user-specific reports, enhance security, and improve the overall functionality of your Tableau dashboard analysis.

Scroll to Top