10. Removing Whitespace from Strings of Text

Overview

Whitespace are spaces that occur either side of a text string. Tableau has a number of functions we can use to remove whitespace, which we will use in this lesson.

To explore more Kubicle data literacy subjects, please refer to our full library.

Summary

Functions used to remove whitespace

LTRIM(): Trims text from the left-hand side of a text string only
TRIM(): Trims text from both sides of a string
RTRIM(): Trims text from the right-hand side of a string only

Transcript

In the previous lesson, we used the split function to isolate the town entry from our address, creating a calculated field called split town. Unfortunately, this left some whitespace on the left-hand side of the town entry. Whitespace is often a problem with datasets, that require manual entry of personal information from users. But it can also be a problem, when we're chopping address data into smaller chunks. Whitespace can occur at the beginning or at the end of a string of text. To remove whitespace and tableau, we use the TRIM functions. There are three TRIM functions in all. LTRIM for left trim, RTRIM for right trim, and TRIM.

LTRIM just trims the left-hand side of the particular string. Let's see it in action by double clicking, and wrapping our current field within the LTRIM function. And as you can see, this removes the whitespace and our split town field is now clean.

If I apply RTRIM which trims the right-hand side of the string, the whitespace in the left-hand side reappears again. And then if I use TRIM, which trims both the right and the left, the whitespace is again removed. As I mentioned previously, when you have data fields entered manually by users, it's always worth using the TRIM function just in case whitespace exists. Although there are many other formula functions in tableau for you to explore. I find that the use cases for these functions are few and far between particularly for non-programmers who do not intend to learn programming as part of their tableau training. However, given an unusual use case that you may be faced with, it could be worth exploring some new functions that you think might help. But as always in these situations, tableau comes with a health warning. So much happens behind the scenes that at the beginning when using a new function, always test with a hand calculation or an Excel, to make sure you're using the new function correctly.

>
Formulas in Tableau
Further Formulas in Tableau

Contents

My Notes

You can take notes as you view lessons.

Sign in or start a free trial to avail of this feature.

Free Trial

Download our training resources while you learn.

Sign in or start a free trial to avail of this feature.

Free Trial