Stringing It Together: Mastering Tableau’s String Functions

A string is a collection of characters, including letters, numbers, and symbols, that represent text-based data in databases and analytics tools. In Tableau, effectively handling strings is essential for data manipulation and visualisation. Mastering string functions in calculated fields allows you to clean up messy data, extract relevant details, and enhance formatting for better insights. In this guide, we’ll dive into some of Tableau’s key string functions with examples.

CONTAINS

“Returns true if the string contains the desired substring”

This can be really useful for quick searches, filtering, and segmenting data. The example shows how all "Printer" products can be identified and filtered.

STARTSWITH/ENDSWITH

“Returns true if the string starts (STARTSWITH) or ends (ENDSWITH) with substring”

These functions are useful for categorising, filtering and grouping strings in Tableau. In this example, "Product Names" have been filtered down using this function to display only those that end with "Table".

FIND

"Returns the position of a substring within a string, or 0 if the substring isn't found"

This can be useful for extracting information, filtering and categorising data, cleaning inconsistencies, and parsing text by locating specific substrings within a field. The example identifies where the substring "John" is located in "Customer Name".

FINDNTH

"Returns the position of the nth occurrence of a substring within a string, or 0 if that occurrence of the substring isn't found"

This has similar uses to the FIND function above but if there are multiple occurrences of the same substring you can find the position of the specific one you are interested in, as is demonstrated in the example below with the second "-" in "Order ID".

LEFT/RIGHT

"Returns the specified number of characters from the start (LEFT) or end (RIGHT) of the given string"

These are used for extracting specific portions of text, such as prefixes, suffixes, or standardised codes. They help with data cleaning, categorisation, formatting consistency, and splitting structured text fields like order numbers or product codes as has been done in this example.

LEN

"Returns the number of characters in the given string"

LEN is useful for data validation, quality checks, and text analysis, and can help identify inconsistencies, detect missing or extra characters, standardise field lengths, and optimise filters or calculations based on text length.

LOWER/UPPER

"Coverts a text string to all lowercase (LOWER) or uppercase (UPPER) letters"

These help to standardise text formatting, ensuring consistency in filters, joins, and comparisons by converting text to a uniform case. They help with case-insensitive matching, data cleaning, and improving search accuracy.

MID

"Returns the characters from the middle of a text string given a starting position and a length"

MID helps with data parsing, cleaning structured text fields, and isolating key information such as product codes, region identifiers, or order numbers as has demonstrated with Order ID in this example.

REPLACE

"Returns a string in which every occurrence of the substring is replaced with the replacement string"

This function allows users to correct errors, update outdated values, clean inconsistent data, or modify content in text fields without altering the structure of the entire dataset. In this case, "Printer" needs to be replaced with "Scanner".

SPLIT

"Returns a substring from a string, as determined by a delimiter extracting the characters from the beginning or end of the string"

This is useful for data extraction, parsing structured data, and separating key pieces of information (like splitting a full name into first and last names or breaking down product codes). In the example, "Order ID" has been split by the "-" delimiter and the 3 specifies that Tableau needs to return the third segment of the string.

SPACE

"Returns a string composed of the specified number of spaces"

SPACE is useful for adding blank spaces to text to improve formatting, create visual separation, or align text in tables and dashboards. In this example, SPACE is combined with the REPLACE function, meaning if customer name was stored in the "John,Doe" format, the comma would be replaced with a space for readability.

RTRIM/LTRIM/TRIM

"Returns the string with leading (LTRIM), trailing (RTRIM) or both spaces removed (TRIM)"

These functions clean user-input data by removing unwanted spaces, ensuring accurate joins and filters, and improving report consistency. The Sample Superstore data is already well-formatted, but in the example below, this function would remove any spaces on either side of "Customer Name" if they existed.

Author:
Amy Peacham
Powered by The Information Lab
1st Floor, 25 Watling Street, London, EC4M 9BR
Subscribe
to our Newsletter
Get the lastest news about The Data School and application tips
Subscribe now
© 2025 The Information Lab