Common String Functions

There are common string functions are the useful in Tableau, many of which would be most useful during the data cleaning process.

What is a string?

A string is a data type that is a series of characters displayed with single or double quotation marks. In Tableau

Common String Functions

When creating a calculated field, a calculation pane can be found on the left and a search bar can be found in a gray pain on the right. Above the search bar is a dropdown menu with calculations categorized by function. When choosing "String," numerous string functions can be found in this category. Below are some of the most useful string functions.

LEFT / RIGHT

LEFT and RIGHT string functions both return the specified number of characters from a string. For the LEFT function, a specified number of characters will be returned from the start of the string, and for the RIGHT function, a specified number of characters will be returned from the end of the string. Below is a calculation using the LEFT function used with the Superstore data set as well as the result of both LEFT and RIGHT functions for the same data set

Calculation using the LEFT function
Result of Calculations for both the LEFT and RIGHT Functions

REPLACE

The REPLACE function searches a given string for a specified substring and replaces it with a specified replacement. Below is a calculation of the LEFT calculation used with the Superstore data set as well as the result of both LEFT and RIGHT functions for a sample of that data set.

Calculation using the REPLACE function
Result of Calculations for the REPLACE Function

CONTAINS

The CONTAINS function will return "True" if the given string contains the specified substring.

Calculation using the CONTAINS function
Result of Calculations for the CONTAINS Function

SPLIT

The SPLIT function splits apart a string and returns a substring (i.e., a part) from the string itself. The calculation includes 3 parts:

  • String: this can be a single string 'Name' or a field [Customer Name].
  • Delimiter: The character or space that separates the substrings (i.e., '-').
  • Token Number: The part of the string to return, after the delimiter. Note a positive number instructs the function to work from left to right, while a negative number instructs the function to work from right to left.
Calculation using the SPLIT function
Result of Calculations for the SPLIT Function

FIND

The FIND function returns the position of a substring within entire string. The first character in the string is position 1. Below, the FIND function was used to identify the position of 'e' in each string.

Calculation using the FIND function
Author:
Samantha Fitzsimmons
Powered by The Information Lab
1st Floor, 25 Watling Street, London, EC4M 9BR
Subscribe
to our Newsletter
Get the lastest news about The Data School and application tips
Subscribe now
© 2024 The Information Lab