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.

string functions in tableau
String Functions In Tableau

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:

  1. ASCII 
  2. CONTAINS 
  3. FIND 
  4. LEFT 
  5. LEN 
  6. MID 
  7. REGEXP_MATCH 
  8. REGEXP_REPLACE 
  9. SPLIT 
  10. TRIM 

1. ASCII 

This returns the ASCII code value of the first character in a string 

ASCII ( String ) 

ASCII (“authors”) = 97 

2. CONTAINS 

This returns a TRUE if the specified substring is present in the given string. 

CONTAINS ( String, Substring ) 

CONTAINS (“Calculation” , “alcu”)  

3. FIND 

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 

4. LEFT 

LEFT ( Stringnum_chars) 

This returns the specified number of characters from the start of the given string. 

LEFT (“Calculation”, 5 ) = “Calcu” 

5. LEN 

LEN (String) 

This returns the number of characters in the given string. 

LEN (“Calculation”) = 11 

6. MID 

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” 

7. REGEXP_MATCH 

REGEXP_MATCH ( String , Pattern ) 

This returns true if a substring of the provided string matches the regular expression pattern. 

REGEXP_MATCH ( ‘ - ( [1234] . [ The.Market] ) -’ ,  ‘\ [\s*(w*\.)  (  \w*\s*\]) ‘ ) = true 

8. REGEXP_REPLACE 

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’ 

9. SPLIT 

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’ 

10. TRIM 

TRIM (String) 

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.

Call Now Button