Summary
This article provides a comprehensive overview of the Tableau `CONTAINS` function, which is essential for analysts who need to determine if a specific word, code, or phrase exists within a text field.

Problem Definition
Analysts frequently encounter scenarios where they need to verify if a text field contains a particular word or phrase. Common questions include:
- Does the customer name include a certain brand?
- Does the comment contain a keyword we want to classify?
- Does the URL include a tracking parameter?
- Does the product description mention a feature?
This situation represents a common filter and classification challenge. The goal is not to match the entire field but to identify whether a specific piece of text appears within it. The `CONTAINS` function in Tableau addresses this analytical problem effectively.
Key Concept of the Tableau CONTAINS Function
The `CONTAINS` function checks if one string appears within another string. It returns a logical result:
- True if the text is found
- False if the text is not found
The core idea is substring matching. This function is particularly useful when the exact field value is unknown or when the value may contain additional text surrounding the relevant part. For instance, if a field contains “North America – Enterprise,” you may want to check if it includes “Enterprise” without needing an exact match.
Data Example for the Tableau CONTAINS Function
Consider the following simple table:
| Customer | Notes |
|---|---|
| Acme Corp | Renewal due next month |
| Blue Peak | Enterprise account |
| Northwind | Trial user |
| Summit Co | Enterprise expansion planned |
If the business question is: “Which accounts are enterprise accounts?” you do not need an exact match on the Notes field. Instead, you want to check if the word “Enterprise” appears anywhere in the text. Using the `CONTAINS` function, the expected result would be:
| Customer | Notes | Contains “Enterprise” |
|---|---|---|
| Acme Corp | Renewal due next month | False |
| Blue Peak | Enterprise account | True |
| Northwind | Trial user | False |
| Summit Co | Enterprise expansion planned | True |
This approach is beneficial because the text is not normalized into a clean category column. The keyword appears within a longer sentence, which suffices for analysis.
Tool Implementation of the Tableau CONTAINS Function
What Tableau CONTAINS Is
In Tableau, the `CONTAINS` function is a string function used to check if one text value exists within another.
Syntax
CONTAINS(string, substring)
Example
CONTAINS([Notes], "Enterprise")
This expression checks whether the value in the `Notes` field includes the text “Enterprise.”
How to Read It
- string: This is the field you are searching.
- substring: This is the text you want to find.
The result is a Boolean value:
- True when the substring exists
- False when it does not
Applied Example of the Tableau CONTAINS Function
Suppose you want to classify accounts based on whether their notes mention enterprise status. The expression would be:
CONTAINS([Notes], "Enterprise")
The expected result would be:
| Customer | Notes | Result |
|---|---|---|
| Acme Corp | Renewal due next month | False |
| Blue Peak | Enterprise account | True |
| Northwind | Trial user | False |
| Summit Co | Enterprise expansion planned | True |
This result can be utilized in a filter, a calculated field, or a segment label. For instance, you could create a field called “Enterprise Flag” and use it in a worksheet to differentiate enterprise accounts from others.
Why the Tableau CONTAINS Feature Exists
Tableau often requires text logic that extends beyond exact matching. A field may contain a sentence, a path, a label, or a mixed-format string. Using exact comparison logic only matches full values, which can be too strict for many analytical tasks. The `CONTAINS` function allows you to search within a string instead of matching the entire string.
This feature is particularly useful when:
- The source system stores free text
- The text contains multiple attributes in one field
- You need keyword-based classification
- You want a quick filter without preprocessing the data
Important Behavioral Details of the Tableau CONTAINS Function
Case Sensitivity
In Tableau, the `CONTAINS` function is case-sensitive. For example:
CONTAINS("Enterprise account", "Enterprise")returns TrueCONTAINS("Enterprise account", "enterprise")returns False
This can lead to confusion. If you require case-insensitive matching, normalize the text first using a function like `LOWER()`. For example:
CONTAINS(LOWER([Notes]), "enterprise")
Null Behavior
If the source field is null, the result will not be True. Null handling is crucial in filters and calculated fields. You may need to wrap the expression with logic that manages missing values based on your business rules.
Partial Matching Only
The `CONTAINS` function does not check word boundaries. For instance, if you search for “pro,” it will also match strings like “product” and “profile.” This behavior can be useful or may lead to false positives, so choose your search text carefully.
Not a Pattern Matching Engine
The `CONTAINS` function is designed for simple substring checks. If you require more advanced text logic, such as complex pattern matching, a regular expression function is typically a better choice.
Filter Behavior
Since the expression returns a Boolean value, it is commonly used as a filter. This makes it practical for dashboards where users need to isolate rows that mention a specific keyword. The logic is straightforward, but the outcome depends on the exact string stored in the field.
Real Usage Patterns for the Tableau CONTAINS Function
Common use cases for the `CONTAINS` function include:
- Keyword tagging for support cases
- Classifying free-text comments
- Detecting campaign parameters in URLs
- Identifying product mentions in descriptions
- Filtering records by labels stored inside text fields
- Creating quick yes or no flags for dashboards
Here are a few practical examples:
- Find all tickets that contain “refund.”
- Flag all URLs that contain “utm_source.”
- Classify accounts whose title contains “Enterprise.”
- Identify order notes that mention “rush.”
These patterns frequently arise in Tableau work because source data is not always cleanly structured. The `CONTAINS` function provides analysts with a straightforward method to work with semi-structured text within a worksheet.
Practical Guidance for Using the Tableau CONTAINS Function
Utilize the `CONTAINS` function when the business question revolves around presence rather than exact equality. If the source system already provides a proper category field, use a cleaner dimension, as this typically yields more reliable analysis.
When relying on the `CONTAINS` function for reporting logic, ensure that the search text is stable and well-defined. Minor changes in wording can significantly impact the results. For example:
- “Enterprise”
- “Enterprise Account”
- “Enterprise customer”
While these may appear similar to a human, they are distinct strings. Therefore, the `CONTAINS` function is best suited for lightweight classification and filtering, rather than serving as a replacement for structured data modeling.