In Tableau, strings or string data, are data made of text. String functions exist to help you manipulate your string data. There about twenty string functions in Tableau. In this article, I am going to introduce you to ten (10) important string functions in Tableau, and how to use them.
You might be wondering “why are string functions so important?” Let’s assume a scenario where you want to pull the first name of all your customers into a new field; a string function will handle that task for you.
Important String Functions in Tableau
Please note that all the string functions in Tableau are of extreme importance. This article is just exploring 10 of them, and they include:
This returns the ASCII code value of the first character in a string
ASCII ( String )
ASCII (“authors”) = 97
This returns a TRUE if the specified substring is present in the given string.
CONTAINS ( String, Substring )
CONTAINS (“Calculation” , “alcu”)
This returns the position of the specified substring within the given string and returns 0 if the substring is not found.
FIND (String, Substring, [ Start ])
The first character in the string is position 1 (not a 0 index).
FIND (“Calculation”, “alcu”) = 2
If the start argument is defined, any instance of the substring that appears before the start position are ignored
FIND (“Calculation”, “a”, 3 ) = 7
LEFT ( String, num_chars)
This returns the specified number of characters from the start of the given string.
LEFT (“Calculation”, 5 ) = “Calcu”
This returns the number of characters in the given string.
LEN (“Calculation”) = 11
MID (String, Start, [length])
This returns the characters from the middle of a text string given a starting position and a length. The first character in the string is in position 1. If the length is not included, all characters to the end of the strings are not returned.
MID (“Tableau Software”, 9 ) = “Software”
If the length is included, up to that many characters are returned.
MID (“Tableau Software”, 2, 4) = “able”
REGEXP_MATCH ( String , Pattern )
This returns true if a substring of the provided string matches the regular expression pattern.
REGEXP_MATCH ( ‘ - (  . [ The.Market] ) -’ , ‘\ [\s*(w*\.) ( \w*\s*\]) ‘ ) = true
REGEXP_REPLACE ( String, Pattern, replacement)
This returns a copy of a given string where the matching pattern is substituted with the replacement string.
REGEXP_REPLACE ( ‘abc123’, ‘\s’, ‘-’ ) = ‘abc--123’
SPLIT ( String , delimiter, token number)
This returns a substring from a string as determined by a delimiter (a separator) extracting the characters from the beginning or end of the string.
SPLIT (‘a/b/c/d’ , ‘ / ‘ , 2 ) = ‘b’
A negative token number can also be used.
SPLIT (‘a/b/c/d’ , ‘ / ‘ , -2 ) = ‘c’
This returns the string with both leading (LTRIM is used for this only ) and trailing (RTRIM is used for this only ) whitespaces removed.
TRIM (“ Budget ”) = “Budget”
To learn more about all the string functions in tableau, click here.