Not everyone is a Tableau guru, at least not yet. To help Tableau rookies, we’re starting from square one with the Tableau Essentials blog series. The series is intended to be an easy-to-read reference on the basics of using Tableau Software, particularly Tableau Desktop. Since there are so many cool features to cover in Tableau, the series will include several different posts.
We are up to part four of our functions articles. In this article, we’ll cover String Functions. Check out the previous ones for Logical Functions, Number Functions and Date Functions. Those articles will also cover how to get to the Calculated Field window where you can use the functions in Tableau Desktop to create or edit a calculated field.
To see all of the String Functions, select String from the Functions drop-down menu like so:
There are quite a few String Functions, so let’s jump right in:
ASCII Function
ASCII(string)
The ASCII function returns the ASCII code for the first character in the string. Here’s an example:
CHAR Function
CHAR(integer)
This function works in the reverse of the ASCII function. It converts an integer ASCII code into a character. Here’s an example:
CONTAINS Function
CONTAINS(string, substring)
The CONTAINS function will return a TRUE value if the string contains the substring and a FALSE if it does not. Example:
ENDSWITH Function
ENDSWITH(string, substring)
A similar function to the one above, the ENDSWITH functions tests if the string ends with the selected substring, returning either TRUE or FALSE. Example:
FIND Function
FIND(string, substring, [start])
The FIND function returns the start of the substring within the string. The first character in the string is position 1. If the substring is not found, it will return a value of 0.
If the start argument is also defined, any instance of the substring that appears before the start will be ignored. Example:
ISDATE Function
ISDATE(string)
This is a logical test that is also included in the list of logical functions. It tests a string to determine if it is a valid date (true/false). This function is also included in the Date Functions.
LEFT Function
LEFT(string, num_chars)
This function returns the characters of the string using the specified number as the amount. Example:
If the start_of_week is omitted, then it is determined by the data source.
LEN Function
LEN(string)
The LEN function (or length function) returns the character count of the given string field. Example:
LOWER Function
LOWER(string)
This function converts all characters in the given string into lower case letters. Example:
LTRIM Function
LTRIM(string)
This function will remove any spaces starting the string. Example:
MAX Function
MAX(a, b)
The MAX function exists in several categories of functions, including String Functions. When used for strings, the MAX function returns the value that is highest in the sort sequence defined by the database for that field’s column. If either field is NULL, then the function will return NULL. Example:
MID Function
MID(string, start, [length])
The MID function returns the characters from the middle of a text string. The start argument is where the returned value will begin and the length argument is how many characters will be returned. If the length is not included, then all remaining characters after the start position will be included. The first character in the string is position 1. Example:
MIN Function
MIN(a, b)
Similar to the MAX function, the MIN function returns the minimum between a and b, which must be of the same data type (i.e. string). With strings, the MIN function will return the lower value based on the sort sequence as defined in the database. If either argument is NULL, then this function will return NULL. Example:
REPLACE Function
REPLACE(string, substring, replacement)
This function will replace find any occurrence of the substring in the string and replace those characters with the replacement string. If the substring is not found in the string, then there is no change. Example:
RIGHT Function
RIGHT(string, num_chars)
This is the opposite of the LEFT function. It returns the characters from the end of a given string, the amount determined by the number of characters argument. Example:
RTRIM Function
RTRIM(string)
The partner function to LTRIM. The RTRIM function returns the string with any trailing spaces removed. Example:
SPACE Function
SPACE(number)
The SPACE function returns a string with the number of spaces defined by the number argument. Example:
STARTSWITH Function
STARTSWITH(string, substring)
This is the opposite of the ENDSWITH function, and it returns a TRUE or FALSE result if the string starts with the substring. Example:
TRIM Function
TRIM(string)
The TRIM function removes any leading or trailing spaces from the string. Example:
UPPER Function
UPPER(string)
Finally, the UPPER function works in opposite to the LOWER function. It takes all the characters in the string and converts them to uppercase characters. Example:
Calculated Fields
Calculated fields can add a whole new layer of insight to your Tableau dashboards. The possibilities are practically endless, but we’ll be covering the fundamentals, especially functions, to help you build a foundational understanding of how and when to use them. Check back for more posts covering:
- Logical Functions
- Number Functions
- Date Functions
- String Functions
- Type Conversion
- Aggregate Functions
- User Functions
Another great resource for functions is Dan Murray’s best-selling guidebook, “Tableau Your Data!” It features a whole section devoted the functions we’ll be covering in this series and much, much more.
More Tableau Essentials
Want to learn more about Tableau? We have several posts outlining all of Tableau’s fantastic features. Check out the full list on our Tableau Essentials blog channel.
As always, let us know if you have any questions or comments about this post or Tableau in general. If you’re looking for personalized training or help with something bigger, contact us directly!