简体   繁体   中英

How to group string values using the calculated field in tableau prep

I would like to group string values but I always got syntax error.

Here's what I would like to achieve: I have a position column contains values like accountant, finance, IT, HR, admin and so on. But I am only interested in those who are in HR position. therefore I would like to group HR related position and non-HR related positions.

I tried using if, contains and or function but failed.

here's my code:

IF (CONTAINS([Position],“HR”) OR

(CONTAINS([Position],“hr”)  OR

(CONTAINS([Position],“Human Resource”) OR

(CONTAINS([Position],“ Human Resource ”)


THEN "HR-Related" 
ELSE "Non-HR Related"
end

Each of the opening brackets need a corresponding closing bracket. You could either

(CONTAINS([Position],"HR"))

to ensure 2 opening and 2 closing brackets, or perhaps a cleaner example would be to remove the initial opening bracket

CONTAINS([Position],"HR")

This example also highlights a small but important difference between a double quotation mark - " " and a set of left double quotation mark and right double quotation mark - “ ” .

Tableau will not accept left/right quotation marks (UNICODE U+201C and U+201D) for defining a string value as done CONTAINS([Position],“HR”) . It will accept a string value for double quotation mark (UNICODE U+0022) as done in "HR-Related" .

The following formula should resolve the syntax errors:

IF 
CONTAINS([Position],"HR") OR
CONTAINS([Position],"hr")  OR
CONTAINS([Position],"Human Resource") OR
CONTAINS([Position]," Human Resource " )
THEN "HR-Related"
ELSE "Non-HR Related"
END

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM