Tableau function User

Tableau ISMEMBEROF to SQL

ISMEMBEROF("Managers") is true when the viewer is in the Managers group on Tableau Server or Cloud. In SQL, groups live in an entitlements table (user, group), and the test is an EXISTS against it for the viewer. The sample's entitlements list mai and linh as Managers and bao in Field; the stand-in viewer TIN\analyst is in no group.

Updated · Checked on the xmetric engine

What is the syntax?

ISMEMBEROF("group")
group
a string constant: the Tableau Server or Cloud group name, such as 'Managers'.

Returns a boolean: true when the viewer belongs to the named Tableau group. The same value on every row.

What does it return, and what is the SQL?

Each example runs on the same 6 sample rows twice: the Tableau formula on the xmetric engine, and the SQL in DuckDB.

Is the viewer a manager?

Tableau

ISMEMBEROF('Managers')

SQL (DuckDB)

WITH viewer AS (
  SELECT 'TIN\analyst' AS username
), entitlements(username, grp) AS (
  VALUES ('mai', 'Managers'), ('linh', 'Managers'), ('bao', 'Field')
)
SELECT
  EXISTS (
    SELECT 1
    FROM entitlements e, viewer v
    WHERE e.username = v.username AND e.grp = 'Managers'
  ) AS result
FROM input
ORDER BY id

False on every row: the viewer has no entitlement rows.

Result
false
false
false
false
false
false

The Tableau formula and the SQL return the same 6 rows.

How do managers see every row and others only their own?

Tableau

IF ISMEMBEROF('Managers') OR [Owner] = USERNAME() THEN [Sales]
END

SQL (DuckDB)

WITH viewer AS (
  SELECT 'TIN\analyst' AS username
), entitlements(username, grp) AS (
  VALUES ('mai', 'Managers'), ('linh', 'Managers'), ('bao', 'Field')
)
SELECT
  CASE
    WHEN EXISTS (
    SELECT 1
    FROM entitlements e, viewer v
    WHERE e.username = v.username AND e.grp = 'Managers'
  ) OR i.Owner = (
    SELECT username
    FROM viewer
  ) THEN i.Sales
    END AS result
FROM input i
ORDER BY i.id

The viewer is not a manager, so only rows 1 and 4, their own, keep a value.

OwnerSalesResult
TIN\analyst420420
mai310null
bao150null
TIN\analyst275275
90null
linh515null

The Tableau formula and the SQL return the same 6 rows.

Where does a straight translation go wrong?

Common mistake

Why does joining to the entitlements table drop every row?

An inner join keeps only rows with a matching entitlement. The viewer has none, so all six rows vanish, even the two they own. Test membership with EXISTS (or a LEFT JOIN) so the data rows stay.

Tableau

ISMEMBEROF('Managers') OR [Owner] = USERNAME()

Tempting SQL

WITH viewer AS (
  SELECT 'TIN\analyst' AS username
), entitlements(username, grp) AS (
  VALUES ('mai', 'Managers'), ('linh', 'Managers'), ('bao', 'Field')
)
SELECT e.grp = 'Managers' OR i.Owner = v.username AS result
FROM input i JOIN viewer v ON TRUE JOIN entitlements e ON e.username = v.username
ORDER BY i.id

SQL that matches

WITH viewer AS (
  SELECT 'TIN\analyst' AS username
), entitlements(username, grp) AS (
  VALUES ('mai', 'Managers'), ('linh', 'Managers'), ('bao', 'Field')
)
SELECT
  EXISTS (
    SELECT 1
    FROM entitlements e
    WHERE e.username = v.username AND e.grp = 'Managers'
  ) OR i.Owner = v.username AS result
FROM input i, viewer v
ORDER BY i.id
OwnerTableauTempting SQLSQL that matches
TIN\analysttruenulltrue
maifalsenullfalse
baofalsenullfalse
TIN\analysttruenulltrue
nullnullnull
linhfalsenullfalse

The SQL that matches returns the Tableau result on every row; the marked cells are where the tempting SQL differs.

How do I write it in Snowflake or BigQuery?

The first example, written for each warehouse from its documentation. These are not run here; DuckDB is.

Snowflake

SELECT
  EXISTS (
    SELECT 1
    FROM entitlements e
    WHERE e.username = $ viewer AND e.grp = 'Managers'
  ) OR Owner = $ viewer AS result
FROM input
ORDER BY id

Snowflake documentation

BigQuery

SELECT
  EXISTS (
    SELECT 1
    FROM entitlements e
    WHERE e.username = @ viewer AND e.grp = 'Managers'
  ) OR Owner = @ viewer AS result
FROM input
ORDER BY id

BigQuery documentation

What does your own ISMEMBEROF formula return?

Edit the formula and run it on the 6 sample rows. Fields: [id], [Region], [Owner], [OwnerName], [Sales].

Runs in your browser on the xmetric engine. Nothing is uploaded.

Which functions go with it?

What do people ask about ISMEMBEROF?

How do I get the Tableau user into the database?

The database only knows the account Tableau connects with. Pass the viewer in: Tableau's Initial SQL can use the [TableauServerUser] parameter, or your app sets a session variable or a query parameter. Then filter with it, as the viewer table does on this page.

What does it return in Tableau Desktop?

When you are signed in to Tableau Server or Cloud, the server's user. Otherwise Desktop uses your local or network identity. Test row-level security as a real viewer on the server, not from Desktop.

Is everyone a member of All Users?

On Tableau Server and Cloud every user is in the All Users group, so ISMEMBEROF("All Users") is true for any signed-in viewer. In Tableau Desktop, not signed in, there are no groups to belong to.

Where is this documented?