This article introduces string functions and their uses in Tableau. It also demonstrates how to create a string calculation using an example.
Why use string functions
String functions allow you to manipulate string data (i.e. data made of text). Tableau uses the current International Components for Unicode (ICU) library when comparing strings. The way strings are sorted and compared is based both on language and locale, and it’s possible for vizzes to change as the ICU is continuously updated for better language support.
For example, you might have a field that contains all of your customers' first and last names. One member might be: Jane Johnson. You can pull the last names from all your customers into a new field using a string function.
The calculation might look something like this:
SPLIT([Customer Name], ' ', 2)
SPLIT('Jane Johnson' , ' ', 2) = 'Johnson'.
String functions available in Tableau:
Returns the ASCII code for the first character of
Returns the character encoded by the ASCII code
Returns true if the given string contains the specified substring.
Returns true if the given string ends with the specified substring. Trailing white spaces are ignored.
Returns the index position of
Returns the position of the nth occurrence of substring within the specified string, where n is defined by the occurrence argument.
Note: FINDNTH is not available for all data sources.
Returns the left-most number of characters in the string.
Returns the length of the string.
Returns the string with any leading spaces removed.
Returns the maximum of
Returns the string starting at index position
Returns the minimum of
Converts a text string so the first letter of each word is capitalised and the remaining letters are lowercase. Spaces and non-alphanumeric characters such as punctuation also act as separators.
Returns the right-most number of characters in
Returns a string that is composed of the specified
Returns true if
Returns the string with leading and trailing spaces removed.
Returns string, with all characters uppercase.
Create a string calculation
Follow along with the steps below to learn how to create a string calculation.
In Tableau Desktop, connect to the Sample - Superstore saved data source, which comes with Tableau.
Navigate to a worksheet.
From the Data pane, under Dimensions, drag Order ID to the Rows shelf.
Notice that every order ID contains values for country (CA and US, for example), year (2011) and order number (100006). For this example, you will create a calculation to pull only the order number from the field.
Select Analysis > Create Calculated Field.
In the calculation editor that opens, do the following:
Name the calculated field Order ID Numbers.
Enter the following formula:
RIGHT([Order ID], 6)
This formula takes the specified digits (6) from the right of the string and pulls them into a new field.
RIGHT('CA-2011-100006' , 6)= '100006'.
When finished, click OK.
The new calculated field appears under Dimensions in the Data pane. Just like your other fields, you can use it in one or more visualisations.
From the Data pane, drag Order ID Numbers to the Rows shelf. Place it to the right of Order ID.
Notice how the fields differ now.
Tableau Functions (Alphabetical)
Tableau Functions (by Category)