Bird
Raised Fist0
Tableaubi_tool~5 mins

String functions (LEFT, RIGHT, CONTAINS) in Tableau - Step-by-Step Guide

Choose your learning style10 modes available

Start learning this pattern below

Jump into concepts and practice - no test required

or
Recommended
Test this pattern10 questions across easy, medium, and hard to know if this pattern is strong
Introduction
String functions help you work with text data by extracting parts or checking if text contains certain words. This makes it easier to clean, filter, or analyze text in your reports.
When you want to show only the first few letters of a product code to group similar items.
When you need to check if customer comments mention a specific word like 'refund'.
When you want to extract the last few characters from an ID to identify a region or category.
When filtering sales data to include only records where the product name contains 'Pro'.
When creating a new field that shows a short version of a long text description.
Steps
Step 1: Open Tableau and connect to your data source
- Data Source tab
Your data fields appear in the Data pane on the left
Step 2: Create a calculated field
- Data pane, right-click and select 'Create Calculated Field...'
A calculation editor window opens
Step 3: Type the LEFT function formula
- Calculation editor
The formula extracts the first characters from a string
💡 Example: LEFT([Product Name], 3) returns the first 3 letters of Product Name
Step 4: Click OK to save the calculated field
- Calculation editor
The new field appears in the Data pane
Step 5: Repeat steps 2-4 using RIGHT function
- Calculation editor
RIGHT([Order ID], 4) extracts the last 4 characters of Order ID
Step 6: Create a calculated field using CONTAINS function
- Calculation editor
CONTAINS([Comments], 'refund') returns TRUE if 'refund' is in Comments
Step 7: Use these calculated fields in your worksheet
- Rows or Columns shelf or Filters pane
Your visualization updates based on the extracted or filtered text
Before vs After
Before
Product Name column shows full names like 'ProMax 3000', 'Basic Model', 'ProLite'
After
Calculated field with LEFT([Product Name], 3) shows 'Pro', 'Bas', 'Pro' to group products by prefix
Settings Reference
LEFT function
📍 Calculation editor
Extracts the first N characters from a text string
Default: No default, you specify the number of characters
RIGHT function
📍 Calculation editor
Extracts the last N characters from a text string
Default: No default, you specify the number of characters
CONTAINS function
📍 Calculation editor
Checks if a text string contains a specific substring, returns TRUE or FALSE
Default: No default, you specify the substring to find
Common Mistakes
Using LEFT or RIGHT without specifying the number of characters
Tableau requires the number of characters to extract; missing it causes errors
Always include the number of characters, e.g., LEFT([Field], 4)
Using CONTAINS with case-sensitive text expecting case-insensitive match
CONTAINS is case-sensitive, so 'Refund' and 'refund' are different
Use LOWER() function to convert both strings to lowercase, e.g., CONTAINS(LOWER([Comments]), 'refund')
Summary
String functions LEFT, RIGHT, and CONTAINS help extract or check parts of text data.
They are useful for grouping, filtering, or cleaning text fields in Tableau.
Remember to specify the number of characters for LEFT and RIGHT, and handle case sensitivity with CONTAINS.

Practice

(1/5)
1. What does the Tableau function LEFT('Tableau', 3) return?
easy
A. 'Tab'
B. 'bleau'
C. 'Table'
D. 'au'

Solution

  1. Step 1: Understand LEFT function

    The LEFT function extracts characters from the start of a string. Here, it extracts 3 characters from 'Tableau'.
  2. Step 2: Extract first 3 characters

    The first 3 characters of 'Tableau' are 'Tab'.
  3. Final Answer:

    'Tab' -> Option A
  4. Quick Check:

    LEFT('Tableau', 3) = 'Tab' [OK]
Hint: LEFT gets characters from the start of text [OK]
Common Mistakes:
  • Confusing LEFT with RIGHT function
  • Extracting more or fewer characters than specified
  • Assuming it extracts from the end
2. Which of the following is the correct syntax to check if the string 'Data' contains the letter 'a' in Tableau?
easy
A. LEFT('Data', 'a')
B. CONTAINS('Data', 'a')
C. CONTAINS('a', 'Data')
D. RIGHT('Data', 'a')

Solution

  1. 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.
  2. Step 2: Apply to given strings

    To check if 'Data' contains 'a', use CONTAINS('Data', 'a').
  3. Final Answer:

    CONTAINS('Data', 'a') -> Option B
  4. Quick Check:

    CONTAINS('Data', 'a') = TRUE [OK]
Hint: CONTAINS(text, substring) order matters: text first [OK]
Common Mistakes:
  • Swapping the order of arguments in CONTAINS
  • Using LEFT or RIGHT instead of CONTAINS
  • Passing characters as numbers
3. What is the result of RIGHT('Analytics', 4) in Tableau?
medium
A. 'tics'
B. 'Anal'
C. 'ytic'
D. 'naly'

Solution

  1. Step 1: Understand RIGHT function

    RIGHT extracts characters from the end of a string. Here, it extracts 4 characters from 'Analytics'.
  2. Step 2: Extract last 4 characters

    The last 4 characters of 'Analytics' are 'tics'.
  3. Final Answer:

    'tics' -> Option A
  4. Quick Check:

    RIGHT('Analytics', 4) = 'tics' [OK]
Hint: RIGHT gets characters from the end of text [OK]
Common Mistakes:
  • Extracting characters from the start instead of end
  • Counting wrong number of characters
  • Confusing with LEFT function
4. You wrote the formula CONTAINS('Business', Business) in Tableau but it gives an error. What is the problem?
medium
A. The first argument should be a number
B. CONTAINS cannot be used with text
C. LEFT function should be used instead
D. Missing quotes around 'Business' in second argument

Solution

  1. 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.
  2. Step 2: Fix by adding quotes

    Adding quotes around 'Business' in second argument makes it a string literal, fixing the error.
  3. Final Answer:

    Missing quotes around 'Business' in second argument -> Option D
  4. Quick Check:

    CONTAINS('Business', 'Business') works [OK]
Hint: Always quote text strings inside CONTAINS [OK]
Common Mistakes:
  • Using unquoted text instead of string literals
  • Confusing CONTAINS with LEFT or RIGHT
  • Passing numbers instead of text
5. You want to create a calculated field in Tableau that returns TRUE if the first 2 letters of a product code are 'AB' and the code contains '123'. Which formula is correct?
hard
A. CONTAINS([Product Code], 'AB') AND LEFT([Product Code], 3) = '123'
B. RIGHT([Product Code], 2) = 'AB' OR CONTAINS('123', [Product Code])
C. LEFT([Product Code], 2) = 'AB' AND CONTAINS([Product Code], '123')
D. LEFT([Product Code], 2) = 'AB' AND CONTAINS('123', [Product Code])

Solution

  1. Step 1: Check LEFT function usage

    LEFT([Product Code], 2) extracts first 2 letters. We compare it to 'AB' to check the start.
  2. 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.
  3. Step 3: Combine conditions with AND

    Both conditions must be true, so use AND.
  4. Final Answer:

    LEFT([Product Code], 2) = 'AB' AND CONTAINS([Product Code], '123') -> Option C
  5. Quick Check:

    Correct syntax and logic = LEFT([Product Code], 2) = 'AB' AND CONTAINS([Product Code], '123') [OK]
Hint: Use LEFT for start, CONTAINS for anywhere, combine with AND [OK]
Common Mistakes:
  • Swapping LEFT and RIGHT functions
  • Reversing arguments in CONTAINS
  • Using OR instead of AND