LEN: from Tableau to SQL

Counts characters including spaces. Below, 8 sample rows go through the calculation and through the SQL, and both return the same numbers.

Calculated field

LEN([label])

Sample data

labelquantityamountflag
cedar cedar 6512.8True
ORCHID-west66-7.6False
maple-east670null
willow north6825.3True
birch-birch694.9False
pine/south70-1.2null
ash719True
nullnullnullnull

The same calculation as SQL

SELECT length(label) AS result FROM input

Runs the example above.

Result

result
15
11
10
12
11
10
3
null

Same rows from the calculation and from the SQL in DuckDB.

Where a naive translation goes wrong

  • Replacing LEN with length(trim(label)) changes the shown values or null handling.

    Naive SQL

    SELECT length(trim(label)) AS result FROM input
    result
    11
    11
    10
    12
    11
    10
    3
    null

    Matches the calculation

    SELECT length(label) AS result FROM input
    result
    15
    11
    10
    12
    11
    10
    3
    null

Signature

LEN(string)