Tableau String Functions

What are Tableau String Functions?

In a scenario where you need to manipulate the string values in your dataset, Tableau provides a series of functions to convert string to a number, slice strings, find the string size, and convert to uppercase or lowercase. They are used to clean, modify and extract any values that are string values.

Here are some values provided by default in Tableau. In this example, the word size of each country in Europe is calculated.

Tableau String Functions - Europe
Tableau String Functions - Length

The LEN() function is a string function in Tableau that is used to give the length of the string.

Tableau String Functions - Country
Key Takeaways
  • String functions in Tableau are used to manipulate and analyze text data.
  • Tableau String Functions enable tasks such as extracting, replacing, and formatting text within calculated fields.
  • Functions like LEFT, RIGHT, MID, and SPLIT allow you to extract specific portions of a string.
  • Formatting functions such as UPPER, LOWER, and TRIM help standardize text cases and remove extra spaces.
  • Conditional functions like CONTAINS, STARTSWITH, and ENDSWITH check for specific text patterns within a string.
  • Use REPLACE to substitute occurrences of a substring within a text field with another substring.

Types of Tableau String Functions

There are many String functions in Tableau. These functions have different functionalities which can be utilized by the user in a variety of ways. Go through these Tableau String Functions in detail below.

#1 – ASCII Function

This is one of the Tableau String Functions available by default. By using the ASCII function, you can find the ASCII Value of the first word in a given string value.

Tableau String Functions - ASCII - Syntax

It can be used in Tableau for other features, as shown.

Step 1: Open a new workbook in Tableau by selecting “File” – “New.” 

Tableau String Functions - ASCII - Step 1

Step 2: The food consumption in Europe dataset is used for this example. To do so, drag and drop the dataset into the workbook.

Step 2

You can also do the same by clicking on “New Data Source” (or pressing Ctrl+D) and selecting the file type of your choice. It will open the Files application, where you can select the file of your choice.

Tableau String Functions - ASCII - Step 2 - Data Source

Step 3: Click on the first sheet to start working on the example.

Tableau String Functions - ASCII - Step 3
ASCII - Step 3 - Dashboard

Step 4: Create a calculated field to call the ASCII String function in Tableau. The ASCII function can also be used to calculate the first word to ASCII values.

ASCII - Step 4

Step 5: Name the calculated field and call the ASCII value.

Tableau String Functions - ASCII - Step 5

Step 6: In the parentheses, drag and drop the feature “Country” to this.

Tableau String Functions - ASCII - Step 6

Step 7: Then, drag and drop the calculated field in the Country table formed in the Worksheet.

Tableau String Functions - ASCII - Step 7

These are the ASCII values of the first letter of every country in Europe.

Tableau String Functions - ASCII - Step 7 - Europe

#2 – CHAR Function

The CHAR function in Tableau is used to convert integers in ASCII code to their string values. It returns only one value and can be used to find the alphabet for a given number.

Tableau String Functions - Char - Syntax

It can be used in Tableau for other features, as shown.

Step 1: To open a new Tableau Workbook, select “File” – “New.”

Char - Step 1

Step 2: Click on the arrow button next to “Search” and select “Create Calculated Field.”

Char - Step 2

Step 3: Name the calculated field and give an integer in the ASCII range.

Tableau String Functions - Char - Step 3

Step 4: Drag and drop this onto the worksheet and see the result.

Char - Step 4

Step 5: In another example, see how you can use the CHAR function in datasets. The food consumption in Europe is used.

Step 2

Step 6: Create a new calculated field to return the first letter of each country. It can be done by combining the ASCII and CHAR functions.

Char - Step 5

Step 7: Name the calculated field and call the ASCII value inside the CHAR function for the feature “Country.”

Tableau String Functions - Char - Step 6

The CHAR function takes the ASCII value of the first word and converts it into a string. Now, you can display the first letters of all the countries.

Tableau String Functions - Char - Step 6 - letters

#3 – CONTAINS Function

The Contains function in Tableau is used to check whether a given substring from the user exists or not. It is a Boolean function that returns True or False.

Tableau String Functions - Contains - Step 1

In this example, you can check if the string “land” is present in the countries of Europe. To do so, follow the steps below.

Step 1: Use the food consumption in Europe dataset for the countries in Europe.

Step 2

Step 2: Drag and drop “Country” in the “Rows” section.

Step 2

Step 3: Create a new calculated field to use the CONTAINS function.

Contains - Step 3

Step 4: Edit the calculated field and use the “Country” feature with the substring in the following component as shown.

Tableau String Functions - Contains - Step 4

Step 5: Drag and drop this field into the “Rows” section.

Contains - Step 5

The table below is the resulting table.

Tableau String Functions - Contains - Step 5 - table

#4 – ENDSWITH Function

The ENDSWITH function is also a Boolean function to check if a given string ends with a substring given by the user. If yes, it returns “True,” else it returns “False.”

Tableau String Functions - ENDSWITH - Syntax

In this example, you can use the ENDSWITH function to check whether a given country ends with the letter/string of your choice.

Step 1: In a new workbook, drag and drop the dataset of your choice. The food-consumption in Europe dataset is used.

Step 2

Step 2: Place the feature “Country” in the “Rows” section.

Step 2

Step 3: Under the Data Tab, click on the “arrow” next to the “Filter” icon and select “Create Calculated Field.”

Contains - Step 3

Step 4: Use the “Country” feature and the substring of your choice in the parentheses of the ENDSWITH function, as shown.

Tableau String Functions - ENDSWITH - Step 4

Step 5: Place the newly created calculated field in the “Rows” section.

ENDSWITH - Step 5

It is the table.

Tableau String Functions - ENDSWITH - Step 5 - Table

#5 – FIND Function

The FIND function is used to find the index in which a substring is found in a string. It returns the value 0 if the substring does not exist. If it is a substring, the index of the first letter is returned.

Tableau String Functions - Find - Syntax

Using the function, you can find the position of letters in different country names. To do so, you need to create a calculated field. In the same food-consumption in Europe dataset, the following steps can be followed.

Step 1: In the “Rows” section, drag and drop the “Country” feature.

Step 2

Step 2: Create a new calculated field to call the FIND function.

Step 3

Step 4: Call the FIND function with the “Country” feature and the substring of your choice.

Tableau String Functions - Find - Step 4

Step 5: Apply the calculated field and place it in the “Rows” section. You will get the table below.

Find - Step 5
Tableau String Functions - Find - Step 5 - table

#6 – FINDNTH Function

The FINDNTH function is used to return the index of a character’s occurrence in a string. It is used to find the place where the first, second, or the ‘n’th occurrence of that character occurs in the string.

Tableau String Functions - FINDNTH - Syntax

Using the function, you can find the position of letters of different occurrences in different country names. To do so, you need to create a calculated field. You can use the food-consumption in Europe Dataset to continue these steps.

Step 1: Use the “Country” feature in the “Rows” section.

Step 2

Step 2: To use the FINDNTH function, create a new calculated field.

Step 5

Step 4: In the calculated field, edit the name of the country and specify the ‘n’th occurrence of that word in that string.

Tableau String Functions - FINDNTH - Step 4

Step 5: Place the newly created calculated field in the “Rows” and observe the table.

Tableau String Functions - FINDNTH - Step 5
Tableau String Functions - FINDNTH - Step 5 - table

#7 – ISDATE Function

This function in Tableau is used to verify if a given string value is in a date format or not. It can be in any format, such as:

  • MM-DD-YYYY
  • DD-MM-YYYY
  • YYYY-MM-DD

It returns “True” if you provide a date value, else it will return “False.”

Tableau String Functions - ISDATE - Syntax

In this example, to use the ISDATE function, you’ll need a workbook and a calculated field.

Step 1: Create a calculated field. 

Step 3

Step 2: Edit the name of the Calculated field and call the ISDATE function. Write a date in any of the formats mentioned earlier in it.

Tableau String Functions - ISDATE - Step 2

Step 3: Place the field in the worksheet, and it will return the answer.

Tableau String Functions - ISDATE - Step 3

This is where the output is shown.

Tableau String Functions - ISDATE - Step 3 - Output

#8 – LEFT Function

The function is used to return the string from the start till the index number that you have given. It takes the string value/function and an integer value.

Tableau String Functions - Left - Syntax

Here, the Airbnb dataset is used to use the LEFT function on the “Property Type” function.

Step 1: A new calculated field is needed to use the LEFT function.

Step 3

Step 2: Before editing the calculated field, place the “Property Type” in the “Rows” section.

Step 2

Step 3: Edit the calculated field and use any integer within the size of the string.

Tableau String Functions - Left - Step 3

Step 4: Apply the calculations on the table by dragging and dropping it. You can see the final table.

Tableau String Functions - Left - Step 4
Tableau String Functions - Left - Step 4 - table

#9 – LEN Function

It is a string function in Tableau that finds the length of a string. It can be used to find the string size of the features or individual ones.

Tableau String Functions - Len - syntax

It can be used in various features. In this example, you can see how this function is used in the Airbnb dataset of Austin, Texas.

Step 1: To start with, in a new worksheet, place the “Property Type” in the “Rows” component.

Step 2

Step 2: Generate a calculated field for this example.

Step 3

Step 3: Change the name of the calculated field and call the function with the “Property Type” defined in parentheses.

Tableau String Functions - Len - Step 3

Step 4: Place this calculated field in the “Rows.”

Len - Step 4

Observe the final table.

Tableau String Functions - Len - Step 4 - Table

#10 – LOWER Function

This function returns all of the letters in lowercase in Tableau. Given an input string, it converts all letters to lowercase format.

The Airbnb dataset is used to understand this example.

Step 1: Set the “Property Type” in the “Rows” component.

Left - Step 2

Step 2: Then, create a new calculated field for this example.

Tableau String Functions - Contains - Step 3

Step 3: Change the name of the calculated field and call Lower with the “Property Type” defined in parentheses.

Tableau String Functions - Lower - Step 3

Step 4: Place this calculated field in the “Rows” and observe the final table.

Tableau String Functions - Lower - Step 4
Tableau String Functions - Lower - Step 4 - Table

#11 – UPPER Function

Given an input string, the string function converts all letters to uppercase format.

Tableau String Functions - Upper - Syntax

We use the Airbnb dataset to understand this example.

Step 1: Start the process by placing the “Property Type” in the “Rows” component.

Tableau String Functions - Left - Step 2

Step 2: Create a new calculated field to convert strings to uppercase.

Step 2

Step 3: Edit the name and call the UPPER function to do so.

Upper - Step 3

Step 4: Place this calculated field in the “Rows.”

Tableau String Functions - Upper - Step 3

This is the final table.

Tableau String Functions - Upper - Step 4 - table

#12 – STARTSWITH Function

The STARTSWITH function is a Boolean function that checks if a given string starts with a substring given by the user. If yes, it returns “True”. Else, it returns “False.”

In this example, you can use the STARTSWITH function to check whether a given country ends with the letter/string of your choice. Note that this is case-sensitive, so if the first letter is in uppercase, use it the same way.

Step 1: In a new workbook, drag and drop the dataset of your choice. The Airbnb dataset of Austin, Texas, is used.

Tableau String Functions - STARTSWITH - Step 1

Step 2: Place the feature “Property Type” in the “Rows” section.

Tableau String Functions - Left - Step 2

Step 3: Now start the process by creating a new calculated field in this workbook.

Tableau String Functions - Char - Step 5

Step 4: Call the STARTSWITH function with the substring of your choice.

Tableau String Functions - STARTSWITH - Step 4

Step 5: Place the newly created calculated field in the “Rows” section.

Tableau String Functions - STARTSWITH - Step 5

This is the final table.

Tableau String Functions - STARTSWITH - Step 5 - Table

Important Things To Note

  • Use TRIM to remove leading and trailing spaces, ensuring your data is clean and consistent.
  • Use UPPER and LOWER to standardize the case of text data.
  • Combine LEFT, MID, and RIGHT to extract specific parts of a string.
  • Combine IF statements with Tableau string functions for conditional transformations.
  • Avoid using complex string calculations directly in filters, as it can slow down performance.
  • Use Tableau ZN or conditional logic to manage null values in your string calculations.

Frequently Asked Questions (FAQs)

1. Can I combine multiple String Functions in Tableau?

Yes, you can combine multiple Tableau string functions to introduce all sorts of functionalities. For example, you can combine the CHAR and ASCII functions to get the first letter of each string.

FAQ 1

2. Are there any limitations to using String Functions in Tableau?

Yes, there are limitations to using Tableau string functions:

Performance Impact: Complex string manipulations can slow down large data sets.
Case Sensitivity: Some functions are case-sensitive, requiring additional handling.
Data Type Constraints: Tableau String functions are not suitable for numeric or date fields.
Locale Differences: Behavior may vary across different locales and languages.

3. Can I use String Functions with other data types in Tableau?

Yes, you can use integer values for certain Tableau String Functions. For example,

• CHAR accepts an integer as an argument.
• FIND and FINDNTH use integers as arguments.
• ISDATE uses date values.
• LEFT and RIGHT accept integer values to slice a given string to a substring starting from the left or right, respectively.

4. Can I use String Functions in Tableau Prep for data preparation?

Yes, you can use string functions in Tableau Prep for data preparation. For example, you can use string functions to clean, format, and manipulate text data during the data preparation process. These can be applied as shown:

Transform Step: Add a “Clean” or “Calculated Field” step to use string functions.
Aggregations: Use Tableau String Functions to group and clean data before aggregating.
Custom Calculations: Create calculated fields that use string functions for more advanced text manipulation.

Download Template

This article must be helpful to understand the Tableau String Functions, with its formula and examples.

Guide to What is the Tableau String Functions. We explain different types of string function including ASCII, CHAR, Contains, ENDSWITH, etc. with examples, and points to note. You can learn more from the following articles –

Tableau Bins

Tableau Date Functions

Tableau Bridge

Reader Interactions

Leave a Reply

Your email address will not be published. Required fields are marked *