知識庫

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


發佈時間 : 21 Feb 2023
上次修改日期 : 22 Feb 2023

問題

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.
 

環境

  • Tableau Desktop

答案

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
這篇文章是否解決了問題?