Tableau String Functions

Tableau provides various string Functions to format or alter string data. They are Tableau LEN, LTRIM, RTRIM, TRIM, CONTAINS, MID, REPLACE, etc. In this article, we will show you how to use Tableau String Functions with examples.

To demonstrate these Tableau String Functions, we are going to use the below-shown data. As you can see, there are 15 records in this table.

Remember, this is an Excel Worksheet. So, Please refer Connecting to the Excel Files article to understand the connection settings.

Tableau String Functions 1

Tableau String Functions

The subsequent examples will show you the list of String Functions in Tableau

Tableau LEN Function

The Tableau LEN function returns the length of a string. The syntax of this Tableau LEN Function is:

LEN(string)

To demonstrate the Tableau string functions, we have to use Calculated Fields. To create a calculated field, please navigate to Analysis Tab and select Create Calculated Field… option.

Tableau String Functions 2

Selecting the Create Calculated Field… option will open the following window. Here, we renamed the default calculation name as LEN.

The below Tableau LEN statement will find the length of each record in Department column

LEN([Department])
Tableau LEN Function 3

Let me add this Tableau LEN function field to the existing table. Please refer Create Table Report article to understand the process of creating a table

Tableau LEN Function 4

Tableau ASCII Function

The Tableau ASCII function will find the ASCII value of a character. If you pass more than one character, then it will return the ASCII value of the first character. The syntax of this Tableau ASCII Function is:

ASCII(string)

Below statement will find the ASCII values of the records present in Last name column

ASCII([LastName])

Let me add this field to the Rows. From the below screenshot, you can see, it is returning the ASCII value of the first character.

Tableau ASCII Function 5

Tableau CHAR Function

The Tableau CHAR function will convert or return the character for the given ASCII value. The syntax of this Tableau CHAR Function is:

CHAR(number)

For example,

CHAR(ASCII([LastName]))

Let me add this field to a Row shelf. From the below screenshot, you can see, it is returning the ASCII value of the first character.

Tableau CHAR function 6

Tableau CONTAINS Function

The Tableau CONTAINS function returns True if the specified substring is present in the original string; otherwise, it returns false. The syntax of this Tableau CONTAINS Function is:

CONTAINS(string, substring)

The below Tableau contains statement checks whether the records present in the Department column contains Software substring or not.

CONTAINS([Department],'Software')
Tableau CONTAINS function 7

Tableau ENDSWITH Function

The Tableau ENDSWITH function returns True if the original string ends with specified substring; otherwise, it returns false. The syntax of this Tableau EndsWith Function is:

ENDSWITH(string, substring)

The below statement will check whether the records present in the Department column ends with rs or not.

ENDSWITH([Department],'rs')
Tableau ENDSWITH function 8

Tableau STARTSWITH Function

Tableau STARTSWITH is one of the string functions in Tableau. This function returns True if the original string starts with specified substring; otherwise, it returns false. The syntax of this Tableau STARTSWITH Function is:

STARTSWITH(string, substring)

The below Tableau startswith statement checks whether the Department column records start with S or not.

STARTSWITH([Department],'S')
Tableau STARTSWITH function 14

Tableau FIND Function

The Tableau FIND function returns the index position of a substring within the original string. The syntax of this Tableau FIND Function is:

FIND(string, substring)

The below Tableau find statement will find the index position of re in the Department column.

FIND([Department],'re')

Let me add this Tableau find field to Rows shelf.

Tableau FIND function 9

Tableau find function also allows you to use the third argument to specify the starting point.

FIND(string, substring, starting_Index_Position)

The below statement will find the index position of e in the Department column where the lookup with a start at index position 5.

FIND([Department],'e', 5)
Tableau FIND function 10

Tableau FINDNTH Function

The Tableau FINDNTH function returns the index position of the nth occurrence of a sub-string within the original string. The syntax of this Tableau FINDNTH Function is:

FINDNTH(string, substring, Occurrence)

The following statement finds the index position of the second occurrence of e in the Department column.

FINDNTH([Department],'e', 5)
Tableau FINDNTH function 11

Tableau LEFT Function

The Tableau LEFT function returns the leftmost characters up to a specified index position. The syntax of this Tableau LEFT Function is:

LEFT(string, index_position)

The below Tableau left function returns the first five characters from the Department column.

LEFT([Department], 5)

Let me add this Tableau LEFT field to Rows.

Tableau LEFT function 12

Tableau RIGHT Function

The Tableau RIGHT function returns the rightmost characters up to a specified index position. The syntax of this Tableau RIGHT Function is:

RIGHT(string, index_position)

The below Tableau Right function returns the last nine characters from the Department column.

RIGHT([Department], 9)

Let me add this Tableau Right field to the Rows.

Tableau RIGHT function 13

Tableau UPPER Function

The Tableau UPPER function converts all the characters in a string to uppercase. The syntax of this Tableau UPPER Function is:

UPPER(string)

The below Tableau Upper statement will convert the records in the Occupation column to uppercase.

UPPER([Occupation])

Let me add this Tableau Upper field to the Rows shelf.

Tableau UPPER function 15

Tableau LOWER Function

The Tableau LOWER function converts a given string to lowercase. The syntax of this Tableau LOWER Function is:

LOWER(string)

The below Tableau lower function converts the department column records to lowercase.

LOWER([Department])

Let me add this Tableau Lower field to Rows shelf.

Tableau LOWER function 16

Tableau MID Function

The Tableau MID function, also called Tableau substring, returns a substring from the original string. The syntax of this Tableau MID Function or substring is:

MID(string, start_position, length)

This Tableau Substring function accepts three arguments:

  • Original String
  • Starting index position – Substring will start from this position
  • Length (optional) – This is the total length of a substring.

The below Tableau Mid statement will return substring starts at index position five from the Department column.

MID([Department], 5)

Let’s add this Tableau MID field to the Rows shelf.

Tableau MID function 17

The below Tableau Mid function return substring starts at index position five and ends after the substring length reaches to 8.

MID([Department], 5, 8)
Tableau String Functions 18

Tableau REPLACE Function

The Tableau Replace function replaces a substring from the original string with a new string. The syntax of this Tableau Replace Function is:

REPLACE(string, old_substring, new_substring)

This Tableau Replace function accepts three arguments:

  • Original String
  • Old_substring – Substring that you want to find and replace
  • New_substring – This is the new string that will replace the Old_substring

The below Tableau Replace statement will replace the Software term in the Dept column with Web.

REPLACE([Department], 'Software', 'Web')

Let me add this Tableau Replace field to Rows shelf.

 Tableau Replace function 19

Tableau SPACE Function

The Tableau Space function helps you to return empty spaces. The syntax of this Tableau Space Function is:

SPACE(integer)

The below statement will add five empty spaces in between the First Name and Last name. By the way, we are concatenating two strings here!

[First Name] + SPACE(5) + [Last Name]

Let’s add this Tableau Space field to Rows shelf.

Tableau Space function 20

Tableau SPLIT Function

The Tableau Split function is one of the Tableau String functions. This function replaces a substring from the original string using the token number and the sequence. The syntax of this Tableau Split Function is:

SPLIT(string, Sequence, token_number)

The Tableau split string function accepts three arguments:

  • Original String
  • Sequence-Function uses this sequence to split the original string. For example, Comma, space, etc.
  • token_number – Occurrence of the Sequence. For example, Sequence is a comma, and token_number is three means Sub-string will start writing from the character after the third comma and ends before 4th comma
SPLIT([Department], ' ', 2)

Let me add this Tableau Split field to the Rows shelf.

Tableau Split Function 22

Tableau LTRIM Function

The Tableau LTRIM function is one of the Tableau string functions. It removes the empty spaces from the left side of a string. The syntax of the Tableau LTRIM is:

LTRIM(string)

It removes empty spaces from the left side of the Last Name

LTRIM(Spaces)

Let me add this Tableau LTRIM field to the Rows shelf.

Tableau LTRIM Function 21

Let me create a New column by adding 10 extra space before the Last name, and 15 extra spaces after the last Name

SPACE(10) + [Last Name] + SPACE(15)
Tableau TRIM Function 23

We will use this calculated field to explain the RTRIM, and TRIM functions

Tableau RTRIM Function

The Tableau RTRIM function removes empty spaces from the right side of a string. Syntax is:

RTRIM(string)

Below Tableau RTRIM statement will remove empty spaces from the right side of a Spaces column

RTRIM(Spaces)
Tableau RTRIM Function 24

Tableau TRIM Function

The Tableau Trim function is one the Tableau string function, which removes empty spaces from the left and right side of a string. The syntax of this Tableau Trim Function is:

TRIM(string)

The below Tableau Trim statement removes blank spaces from Spaces column

TRIM(Spaces)
Tableau TRIM Function 25