Tableau function User

Tableau FULLNAME to SQL

FULLNAME() returns the viewer's display name, not their login: "Local Analyst", where USERNAME() returns TIN\analyst. In SQL, pass the viewer's full name in alongside the user name and compare it with a column of full names. The sample runs as a stand-in viewer: user name TIN\analyst, full name Local Analyst, domain TIN, in no groups. In SQL the viewer is a one-row viewer table; in production your app passes it in.

Updated · Checked on the xmetric engine

What is the syntax?

FULLNAME()

Returns a string: the full display name of the person viewing, such as "Local Analyst". 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.

What is the viewer's full name?

Tableau

FULLNAME()

SQL (DuckDB)

WITH viewer AS (
  SELECT
    'TIN\analyst' AS username,
    'Local Analyst' AS fullname,
    'TIN' AS domain
)
SELECT v.fullname AS result
FROM input i, viewer v
ORDER BY i.id

One value, repeated on every row.

Result
Local Analyst
Local Analyst
Local Analyst
Local Analyst
Local Analyst
Local Analyst

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

Which rows name the viewer as owner?

Tableau

FULLNAME() = [OwnerName]

SQL (DuckDB)

WITH viewer AS (
  SELECT
    'TIN\analyst' AS username,
    'Local Analyst' AS fullname,
    'TIN' AS domain
)
SELECT v.fullname = i.OwnerName AS result
FROM input i, viewer v
ORDER BY i.id

Rows 1 and 4. Row 5 has no owner name, so the test is null.

OwnerNameResult
Local Analysttrue
Mai Tranfalse
Bao Lefalse
Local Analysttrue
null
Linh Phamfalse

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

Where does a straight translation go wrong?

Common mistake

Why does the full name match no owner?

FULLNAME is the display name. Compared with the Owner column, which holds user names, it never matches. Compare full names with full names, or better, user names with user names: two people can share a display name.

Tableau

FULLNAME() = [OwnerName]

Tempting SQL

WITH viewer AS (
  SELECT
    'TIN\analyst' AS username,
    'Local Analyst' AS fullname,
    'TIN' AS domain
)
SELECT v.fullname = i.Owner AS result
FROM input i, viewer v
ORDER BY i.id

SQL that matches

WITH viewer AS (
  SELECT
    'TIN\analyst' AS username,
    'Local Analyst' AS fullname,
    'TIN' AS domain
)
SELECT v.fullname = i.OwnerName AS result
FROM input i, viewer v
ORDER BY i.id
OwnerNameTableauTempting SQLSQL that matches
Local Analysttruefalsetrue
Mai Tranfalsefalsefalse
Bao Lefalsefalsefalse
Local Analysttruefalsetrue
nullnullnull
Linh Phamfalsefalsefalse

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 OwnerName = $ viewer_fullname AS result
FROM input
ORDER BY id

Snowflake documentation

BigQuery

SELECT OwnerName = @ viewer_fullname AS result
FROM input
ORDER BY id

BigQuery documentation

What does your own FULLNAME 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 FULLNAME?

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.

Where is this documented?