0
0
Tableaubi_tool~5 mins

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

Choose your learning style9 modes available
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.