Tableau Essentials: Calculated Fields – String Functions

Tableau Essentials: Calculated Fields – String Functions

//

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:

String Functions

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:

ASCII(“Alabama”) = 65

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:

CHAR(65) = ‘A’

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:

CONTAINS(“InterWorks”, “Works”) = TRUE

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:

ENDSWITH(“software”, “ware”) = TRUE

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.

FIND(“Oklahoma”, “la”) = 3

If the start argument is also defined, any instance of the substring that appears before the start will be ignored. Example:

FIND(“Mississippi”, “iss”, 4) = 5

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.

ISDATE(“September 29, 2014”) = true

LEFT Function

LEFT(string, num_chars)

This function returns the characters of the string using the specified number as the amount. Example:

LEFT(“cheetah”, 4) = ‘chee’

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:

LEN(“Missouri”) = 8

LOWER Function

LOWER(string)

This function converts all characters in the given string into lower case letters. Example:

LOWER(“Tableau”) = “tableau”

LTRIM Function

LTRIM(string)

This function will remove any spaces starting the string. Example:

LTRIM(“ Harry”) = “Harry”

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:

MAX(“Apple”, ”Banana”) = “Banana”

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:

MID(“Stillwater”, 3, 2) = “il”

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:

MIN(“Apple”, “Banana”) = “Apple”

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:

REPLACE(“calculation”, “ion”, “ed”) = “calculated”

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:

RIGHT(“Nebraska”, 6) = “braska”

RTRIM Function

RTRIM(string)

The partner function to LTRIM. The RTRIM function returns the string with any trailing spaces removed. Example:

RTRIM(“Harry “) = “Harry”

SPACE Function

SPACE(number)

The SPACE function returns a string with the number of spaces defined by the number argument. Example:

SPACE(1) = “ “

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:

STARTSWITH(“Michigan”, “Mic”) = TRUE

TRIM Function

TRIM(string)

The TRIM function removes any leading or trailing spaces from the string. Example:

TRIM(“ Harry ”) = “Harry”

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:

UPPER(“nasa”) = “NASA”

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:

Introduction

  1. Logical Functions
  2. Number Functions
  3. Date Functions
  4. String Functions
  5. Type Conversion
  6. Aggregate Functions
  7. 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!

Want More Tableau Essentials

  1. Tableau Essentials: Chart Types – Introduction
  2. Tableau Essentials: Chart Types – The Text Table
  3. Tableau Essentials: Chart Types – Heat Map
  4. Tableau Essentials: Chart Types – Highlight Table
  5. Tableau Essentials: Chart Types – Symbol Map
  6. Tableau Essentials: Chart Types – Filled Map
  7. Tableau Essentials: Chart Types – Pie Chart
  8. Tableau Essentials: Chart Types – Horizontal Bar Chart
  9. Tableau Essentials: Chart Types – Stacked Bar Chart
  10. Tableau Essentials: Chart Types – Side-by-Side Bar Chart
  11. Tableau Essentials: Chart Types – Treemap
  12. Tableau Essentials: Chart Types – Circle View
  13. Tableau Essentials: Chart Types – Side-by-Side Circle View
  14. Tableau Essentials: Chart Types – Line Charts (Continuous & Discrete)
  15. Tableau Essentials: Chart Types – Dual-Line Chart (Non-Synchronized)
  16. Tableau Essentials: Chart Types – Area Charts (Continuous & Discrete)
  17. Tableau Essentials: Chart Types – Scatter Plot
  18. Tableau Essentials: Chart Types – Histogram
  19. Tableau Essentials: Chart Types – Box-and-Whisker Plot
  20. Tableau Essentials: Chart Types – Gantt Chart
  21. Tableau Essentials: Chart Types – Bullet Graph
  22. Tableau Essentials: Chart Types – Packed Bubbles
  23. Tableau Essentials: Formatting Tips – Introduction
  24. Tableau Essentials: Formatting Tips – Custom Shapes
  25. Tableau Essentials: Formatting Tips – Labels
  26. Tableau Essentials: Formatting Tips – Color
  27. Tableau Essentials: Formatting Tips – Tooltips
  28. Tableau Essentials: Formatting Tips – Maps
  29. Tableau Essentials: Calculated Fields – Introduction
  30. Tableau Essentials: Calculated Fields – Logical Functions
  31. Tableau Essentials: Calculated Fields – Number Functions
  32. Tableau Essentials: Calculated Fields – Date Functions
  33. Tableau Essentials: Calculated Fields – String Functions
  34. Tableau Essentials: Calculated Fields – Type Conversion
  35. Tableau Essentials: Calculated Fields – Aggregate Functions
  36. Tableau Essentials: Calculated Fields – User Functions

Need Expert Help?

See Our Full Menu of Data Services

InterWorks uses cookies to allow us to better understand how the site is used. By continuing to use this site, you consent to this policy. Review Policy OK

×

Interworks GmbH
Ratinger Straße 9
40213 Düsseldorf
Germany
Geschäftsführer: Mel Stephenson

Kontaktaufnahme: markus@interworks.eu
Telefon: +49 (0)211 5408 5301

Amtsgericht Düsseldorf HRB 79752
UstldNr: DE 313 353 072

×

Love our blog? You should see our emails. Sign up for our newsletter!