Tableau function String

Tableau LTRIM to SQL

LTRIM(string) removes the spaces at the start of a string and keeps the ones at the end. DuckDB's ltrim() does the same. trim() is not a shortcut: it strips both sides.

Updated · Checked on the xmetric engine

What is the syntax?

LTRIM(string)
string
the text.

Returns the string without leading spaces. Null if the string is null.

What does it return, and what is the SQL?

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

What is left after removing leading spaces?

Tableau

LTRIM('  ' + [Name] + '  ')

SQL (DuckDB)

SELECT ltrim('  ' || Name || '  ') AS result
FROM input
ORDER BY id

The two trailing spaces stay.

NameResult
Ann LeeAnn Lee
bob raybob ray
Café NordCafé Nord
easteast
EastEast
mary-jo o'neilmary-jo o'neil
null

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

Where does a straight translation go wrong?

Common mistake

Why does trim() lose the trailing spaces?

trim() strips both ends; LTRIM only the start. The difference matters when you later concatenate or pad.

Tableau

LTRIM('  ' + [Name] + '  ')

Tempting SQL

SELECT trim('  ' || Name || '  ') AS result
FROM input
ORDER BY id

SQL that matches

SELECT ltrim('  ' || Name || '  ') AS result
FROM input
ORDER BY id
NameTableauTempting SQLSQL that matches
Ann LeeAnn Lee Ann LeeAnn Lee
bob raybob ray bob raybob ray
Café NordCafé Nord Café NordCafé Nord
easteast easteast
EastEast EastEast
mary-jo o'neilmary-jo o'neil mary-jo o'neilmary-jo o'neil
nullnullnull

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 LTRIM(Name) AS result
FROM input
ORDER BY id

Snowflake documentation

BigQuery

SELECT LTRIM(Name) AS result
FROM input
ORDER BY id

BigQuery documentation

What does your own LTRIM formula return?

Edit the formula and run it on the 7 sample rows. Fields: [id], [Name], [Code], [Email], [Num].

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

Which functions go with it?

What do people ask about LTRIM?

Why are the spaces added inside the formula here?

The sample loader strips spaces around CSV cells, so the examples pad the name in the formula to show what LTRIM removes.

Does LTRIM remove tabs or line breaks?

Tableau documents it for spaces. In DuckDB, pass the characters to strip: ltrim(x, chr(9) || ' ').

Where is this documented?