Was this page helpful?
Yes No

User Functions

This article introduces user functions and their uses in Tableau. It also demonstrates how to create a user calculation using an example.

In this article

Why use user functions

User functions can be used to create user filters or column-level security filters that affect visualizations published to Tableau Server or Tableau Online, so that only certain people can see your visualization.

For example, if you have a visualization that shows the sales performance for each employee in your department published on Tableau Server or Tableau Online, you might want to only allow employees to see their own sales numbers when they access that visualization.

In this case, you can use the ISMEMBEROF function to create a field that returns true if the username of the person signed in to the server is a member of a specified group (on the server), such as the "Managers" group, for example. Then when you filter the view using this calculated field, only a person who is part of that group can see the data.

The calculation in this case might look something like the following:

ISMEMBEROF('Managers')

Note: If your group or user names contain non-alphanumeric characters, you must use HTML URL Encoding for the special characters when using the functions below. For example, the function ISMEMBEROF("USERS+") needs to be written as ISMEMBEROF("USERS%2B"), because the '%2B' is the HTML URL Encoding for the '+' symbol. For information on HTML URL encoding, please see HTML URL Encoding Reference at the W3schools Web Developer site.

User functions available in Tableau:

Functions

Syntax

Description

FULLNAME

FULLNAME( )

Returns the full name for the current user. This is the Tableau Server or Tableau Online full name when the user is signed in; otherwise the local or network full name for the Tableau Desktop user.

Example:

[Manager]=FULLNAME( )

If manager Dave Hallsten is signed in, this example returns True only if the Manager field in the view contained Dave Hallsten. When used as a filter, this calculated field can be used to create a user filter that only shows data that is relevant to the person signed in to the server.

ISFULLNAME

ISFULLNAME(string)

Returns true if the current user's full name matches the specified full name, or false if it does not match. This function uses the Tableau Server or Online full name when the user is signed in; otherwise it uses the local or network full name for the Tableau Desktop user.

Example:

ISFULLNAME(“Dave Hallsten”)

This example returns true if Dave Hallsten is the current user, otherwise it returns false.

ISMEMBEROF

ISMEMBEROF(string)

Returns true if the person currently using Tableau is a member of a group that matches the given string. If the person currently using Tableau is signed in, the group membership is determined by groups on Tableau Server or Tableau Online. If the person is not signed in, this function returns false.

Example:

IF ISMEMBEROF(“Sales”) THEN “Sales” ELSE “Other” END

ISUSERNAME

ISUSERNAME(string)

Returns true if the current user's username matches the specified username, or false if it does not match. This function uses the Tableau Server or Online username when the user is signed in; otherwise it uses the local or network username for the Tableau Desktop user.

Example:

ISUSERNAME(“dhallsten”)

This example returns true if dhallsten is the current user; otherwise it returns false.

USERDOMAIN

USERDOMAIN()

Returns the domain for the current user when the user is signed on to Tableau Server. Returns the Windows domain if the Tableau Desktop user is on a domain. Otherwise this function returns a null string.

Example:

[Manager]=USERNAME() AND [Domain]=USERDOMAIN()

USERNAME

USERNAME( )

Returns the username for the current user. This is the Tableau Server or Tableau Online username when the user is signed in; otherwise it is the local or network username for the Tableau Desktop user.

Example:

[Manager]=USERNAME( )

If the manager dhallsten was signed in, this function would only return True when the Manager field in the view is dhallsten. When used as a filter this calculated field can be used to create a user filter that only shows data that is relevant to the person signed in to the server.


Create a user calculation

User calculations work directly with the users and groups you have set up on Tableau Server or Tableau Online. You can create user calculations to use as filters so users only see the data that is relevant to them.

For example, if you have a map viz similar to the following, which shows sales data for 48 US states, you can create a user calculation to show only parts of the map that are relevant to each user, such as data relevant for a regional manager versus a national manager. (A national manager should be able to see data for the entire country, while a regional manager should only be able to see data for the region they manage).

When the national manger is signed in, they see the following visualization:

When the western regional manager is signed in, they see only sales for their region:

To create a user function that performs similarly to this example, follow the steps below.

Before you begin

To follow along with this example you must have access to Tableau Server or Online. You must also be a Server or Site Administrator.

Step 1: Create the users and groups

  1. Sign in to Tableau Server or Tableau Online.

  2. In Tableau Server or Tableau Online, add the following users:

    • Kelly Williams

    • Chuck Magee

    • Cassandra Brandow

    • Anna Andreadi

    For more information, see Add Users to a Site in the Tableau Server Help.

  3. Create a new group called National Managers.

    For more information, see Create a Local Group in the Tableau Server Help.

  4. Add yourself to the National Managers group.

    For more information, see Add Users to a Group in the Tableau Server Help.

Step 2: Create the visualization

  1. Open Tableau Desktop, and connect to the Sample-Superstore data source, which comes with Tableau.

  2. In the bottom left corner of the workspace, click the Data Source tab.

  3. On the Data Source page, from the Connections pane on the left, drag the People sheet to the join area.

  4. Click the join icon and select Left.

  5. Navigate to a new worksheet.

  6. In the Data pane, under Dimensions, double-click State.

    A map view is created.

  7. From the Data pane, under Measures, drag Sales to Color on the Marks card.

  8. On the Columns shelf, select the Longitude field and hold down Control (Comman on Mac) on your keyboard to copy it. Drag the copy to the right of the original on the Columns shelf.

  9. On the Marks card, click the second (bottom) Longitude tab.

  10. From the Data pane, drag Region to Color on the Marks card.

    The map view on the right updates with new colors.

  11. On the Marks card, click the mark type drop-down and select Map.

  12. On the Marks card, click Color, and, under Opacity, adjust the slider to 50%.

  13. On the Marks card, click the first Longitude tab.

  14. On the Marks card, click Color > Edit Colors, and then select Gray from the color palette drop-down list.

    The map view on the left updates.

  15. On the Columns shelf, right-click the Longitude field on the right and select Dual Axis.

The map looks like the following:

Step 3: Create the User Calculation

  1. Select Analysis > Create Calculated Field.

  2. In the calculation editor that opens, do the following:

    • Name the calculated field, User Filter.

    • Enter the following formula:

      [Region (People)] = USERNAME() OR ISMEMBEROF("National Managers")

      This calculation checks if a person is included in the Region (People) field, or if a person is included in the National Managers group. If so, it returns true.

    • When finished, click OK.

    The new user calculation appears under Dimensions in the Data pane. Just like your other fields, you can use it in one or more visualizations.

Step 4: Add the user calculation to the Filters shelf

  1. From the Data pane, under Dimensions, drag User Filter to the Filters shelf.

  2. In the Filter dialog box that opens, select True, and then click OK.

    Note: If you are not signed in to Tableau Server or Tableau Online, the True option is not visible. In Tableau Desktop, sign in to Tableau Server or Tableau Online to select it. See Sign in to Tableau Server or Online for more information.

Step 5: Test the calculation

  1. In Tableau Desktop, in the bottom-right corner of the workspace, click the Filter as User drop-down and change the user to Anna Andreadi.

    The map updates to show only the West region of the United States because Anna is assigned to the West region in the People sheet.

  2. Select the Filter as User drop-down again and change the user to Kelly Williams.

    The map updates to show only the Central region of the United States because Kelly is assigned to the Central region in the People sheet.

  3. Select the Filter as User drop-down again and change the user to Chuck Magee.

    The map updates to show only the East region of the United States because Chuck is assigned to the East region in the People sheet.

  4. Select the Filter as User drop-down again and change the user to Cassandra Brandow.

    The map updates to show only the South region of the United States because Cassandra is assigned to the South region in the People sheet.

  5. Select the Filter as User drop-down one more time and change the user back to yourself.

    The map updates to show all data because you are a part of the National Managers group on the server.

This behavior persists when you publish the view to Tableau Server or Tableau Online. Users not listed in the National Managers group, or in the People sheet in the Sample Superstore data source see only a blank visualization.

See Also

User Calculations free training video

Functions in Tableau

Tableau Functions (by Category)

Tableau Functions (Alphabetical)