KNOWLEDGE BASE

How to calculate the measure of a field that contains a specific string and other fields


Published: 21 Feb 2023
Last Modified Date: 22 Feb 2023

Question

How to calculate the measure of a field that contains a specific string and other fields.

For example, if you enter "Book", sales in the subcategory containing the string "Book" will be displayed, as well as sales in all other subcategories.
 

Environment

  • Tableau Desktop

Answer

1. Connect to Sample Superstore data source.
2. Create a new parameter like the following.
User-added image
3. Right click on [Enter Sub Category Name] -> Show Parameter
4. Create a new calculated field as following.
     Name : Sales of Specific Sub Category and the others
     Calculation : IF CONTAINS([Sub-Category],[Enter Sub Category Name]) = TRUE
                          THEN [Sub-Category]
                          ELSE "Others"
                          END
5. Drag [Sales of Specific Sub Category and the others] to Rows.
6. Drag [Sales] to Text on Marks.
User-added image
Did this article resolve the issue?