What if you could find and extract exactly the text you need in seconds, not hours?
Why String functions (LEFT, RIGHT, CONTAINS) in Tableau? - Purpose & Use Cases
Start learning this pattern below
Jump into concepts and practice - no test required
Imagine you have a long list of customer names and emails in a spreadsheet. You need to find all customers whose email ends with '@gmail.com' or extract the first three letters of their names to create a quick code. Doing this by scanning each row manually or copying and pasting is exhausting and slow.
Manually searching through thousands of rows is error-prone and takes hours. Copying parts of text by hand leads to mistakes, and filtering emails without automation means you might miss important data or waste time repeating the same steps.
String functions like LEFT, RIGHT, and CONTAINS in Tableau let you quickly extract parts of text or check if certain words or characters exist in your data. This automation saves time, reduces errors, and helps you focus on analyzing results instead of preparing data.
Scan each cell, copy first 3 letters manually
Filter emails by reading each oneLEFT([Name], 3) CONTAINS([Email], "@gmail.com")
With these string functions, you can instantly clean, filter, and categorize text data to uncover insights faster and more accurately.
A marketing analyst uses CONTAINS to find all customers with emails from a specific domain to target a campaign, and LEFT to create short customer codes for quick reference.
Manual text handling is slow and error-prone.
String functions automate text extraction and searching.
They help you analyze data faster and with confidence.
Practice
LEFT('Tableau', 3) return?Solution
Step 1: Understand LEFT function
The LEFT function extracts characters from the start of a string. Here, it extracts 3 characters from 'Tableau'.Step 2: Extract first 3 characters
The first 3 characters of 'Tableau' are 'Tab'.Final Answer:
'Tab' -> Option AQuick Check:
LEFT('Tableau', 3) = 'Tab' [OK]
- Confusing LEFT with RIGHT function
- Extracting more or fewer characters than specified
- Assuming it extracts from the end
Solution
Step 1: Understand CONTAINS syntax
CONTAINS(text, substring) checks if substring exists in text. The first argument is the main text, second is what to find.Step 2: Apply to given strings
To check if 'Data' contains 'a', use CONTAINS('Data', 'a').Final Answer:
CONTAINS('Data', 'a') -> Option BQuick Check:
CONTAINS('Data', 'a') = TRUE [OK]
- Swapping the order of arguments in CONTAINS
- Using LEFT or RIGHT instead of CONTAINS
- Passing characters as numbers
RIGHT('Analytics', 4) in Tableau?Solution
Step 1: Understand RIGHT function
RIGHT extracts characters from the end of a string. Here, it extracts 4 characters from 'Analytics'.Step 2: Extract last 4 characters
The last 4 characters of 'Analytics' are 'tics'.Final Answer:
'tics' -> Option AQuick Check:
RIGHT('Analytics', 4) = 'tics' [OK]
- Extracting characters from the start instead of end
- Counting wrong number of characters
- Confusing with LEFT function
CONTAINS('Business', Business) in Tableau but it gives an error. What is the problem?Solution
Step 1: Check CONTAINS argument types
CONTAINS requires both arguments to be text strings or fields. Here, second argument is missing quotes, so Tableau treats it as a field name.Step 2: Fix by adding quotes
Adding quotes around 'Business' in second argument makes it a string literal, fixing the error.Final Answer:
Missing quotes around 'Business' in second argument -> Option DQuick Check:
CONTAINS('Business', 'Business') works [OK]
- Using unquoted text instead of string literals
- Confusing CONTAINS with LEFT or RIGHT
- Passing numbers instead of text
Solution
Step 1: Check LEFT function usage
LEFT([Product Code], 2) extracts first 2 letters. We compare it to 'AB' to check the start.Step 2: Check CONTAINS usage
CONTAINS([Product Code], '123') checks if '123' is anywhere in the code. The order is correct: main text first, substring second.Step 3: Combine conditions with AND
Both conditions must be true, so use AND.Final Answer:
LEFT([Product Code], 2) = 'AB' AND CONTAINS([Product Code], '123') -> Option CQuick Check:
Correct syntax and logic = LEFT([Product Code], 2) = 'AB' AND CONTAINS([Product Code], '123') [OK]
- Swapping LEFT and RIGHT functions
- Reversing arguments in CONTAINS
- Using OR instead of AND
