Home » Tableau » User Domain Function In Tableau

User Domain Function In Tableau

What is USERDOMAIN Function in Tableau

Tableau USERDOMAIN function is a built-in function that returns the domain name of the current user who is logged in to Tableau Server or Tableau Desktop. The function returns a string that contains the domain name of the current user, such as “mycompany.com”. This can be useful when you need to create a calculated field or filter that takes into account the current user’s domain.

The syntax for using the Tableau USERDOMAIN function is simple.

You can insert the function into a calculated field or into a worksheet filter, like this:

USERDOMAIN()

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

Lets take 3 different examples of using user domain function in Tableau:

Example#1: Display Domain name in Text box

This is the simple example just to show the domain name in a text box in you Tableau dashboard visualization. This is just use to show to the end user that which domain name they fall. its make you dashboard more professional.

"Logged in as " + USERDOMAIN()

This formula will display the text “Logged in as mycomapany” in a text box on a dashboard.

Example#2: Filtering a view based Userdomain Function

You can also use the different dynamic view or as filtering a view based on the user’s domain. suppose you want to design one single dashboard for two different domain users, then you can use tableau USERDOMAIN function to filtering the view based on domain of users

Below code you can use

IF USERDOMAIN() = “domain_name” THEN [Sales] END

This formula will only return the Sales measure if the user’s domain matches “domain_name”. You can use this formula to create a dynamic filter that only shows data relevant to certain users.

Example#3: Customizing a calculation based on the user’s domain

This example is really helpful if you are dealing with multiple domain and try to build single Tableau dashboard. You can use USERDOMAIN function as customizing a calculation field.

Below is the example where calculation is on Profit field which is multiply by 1.1 if match the domain name else it will return simple profit field.

IF USERDOMAIN() = "domain_name" THEN [Profit] * 1.1 ELSE [Profit] END

This formula will apply a 10% markup to the Profit measure for users with the domain “domain_name”, and leave it unchanged for all other users. You can use this technique to customize calculations based on different user groups.