Monday, June 19, 2023

Explain the String Function ' CONTAINS ' in Tableau with Example?

 In Tableau, the "CONTAINS" function is used to determine whether a specified string of characters is present within another string. It returns a Boolean value of "True" if the specified string is found within the original string, and "False" otherwise.


The syntax for the CONTAINS function in Tableau is as follows:


CONTAINS(string, substring)


Here, "string" is the original string in which you want to search, and "substring" is the string you are looking for within the original string.


Let's consider an example to illustrate the usage of the CONTAINS function:


Suppose we have a dataset of customer names and we want to identify customers whose names contain the word "Tech". We can use the CONTAINS function to achieve this.


  • Start by creating a new calculated field. Right-click on a blank area in the "Data" pane and select "Create Calculated Field."

  • In the calculation editor, enter the following formula:

            CONTAINS([Customer Name], "Tech")

            Here, [Customer Name] is the field containing the customer names, and "Tech" is the substring             we want to search for.


  • Provide a name for the calculated field, such as "ContainsTech" and click on the "OK" button.
  • Now, you can use the "ContainsTech" field in your analysis. Drag and drop it onto the filter shelf to filter the data based on the result of the CONTAINS function.


For example, if you want to display only the customers whose names contain "Tech," you can set the "ContainsTech" filter to "True."


The CONTAINS function will return "True" for customer names like "Tech Solutions," "High-Tech Services," "TechMaster," etc., and "False" for names that don't contain the word "Tech."


By using the CONTAINS function in Tableau, you can perform various string matching and filtering operations based on specific patterns or substrings within your data.

No comments:

Post a Comment

If you have any doubts. Please let me know

How can you create an alias for a table in a SQL query?

In SQL, you can create an alias for a table in a query to give the table a temporary, alternative name that you can use in the query. Table ...