Forum Discussion
Create Column
- 6 years ago
Well, that's frankly a horrible construction, doesn't Tableau have a SWITCH/CASE statement?
Use a SWITCH(TRUE()...) statement. Replace CONTAINS with SEARCH or FIND like:
Column?
SWITCH(TRUE(),
SEARCH("AIX 5.3",[OS],,-1 ) <> -1 THEN "AIX 5.3",
SEARCH("AIX 6.1",[OS],,-1 ) <> -1 THEN "AIX 6.1",
...
)
They probably don't need the <> -1, only SEARCH statements should do because they return blank if not found to be considered FALSE so, save yourself some writing. So
Column?
SWITCH(TRUE(),
SEARCH("AIX 5.3",[OS]) THEN "AIX 5.3",
SEARCH("AIX 6.1",[OS]) THEN "AIX 6.1",
...
)
How do I write a formula where I can hit <ENTER> so I can have one row per "search"? When I try to create a column it seems like I am being limited to writing the entire formula on one line. Thank you!
- Greg_Deckler6 years ago
Community Champion
Use Alt-Enter
- phaering6 years ago
Helper I
I created a quick sample of my entire script and received an error message: "Function 'SWITCH' does not support comparing values fo type True/False with values of type Integer. Consider using the VALUE or FORMAT function to convert one of the values."
I have no idea what this means or how to fix it.
Thank you!
- phaering6 years ago
Helper I
Here is the view of what I have entered so far:
Column = SWITCH(TRUE(),
//AIX
SEARCH("AIX 5.3",[OS],"AIX 5.3",
SEARCH("AIX 6.1",[OS],"AIX 6.3",
SEARCH("AIX 7.1",[OS],"AIX 7.1",
SEARCH("AIX VIOS 6.1",[OS],"AIX 6.1",
//HPUX
SEARCH("HP-UX B.11.11",[OS],"HPUX 11.11",
SEARCH("HP-UX B.11.23",[OS],"HPUX 11.23",
SEARCH("HP-UX B.11.31",[OS],"HPUX 11.31",
//Linux Other
SEARCH("CentOS 4.8",[OS],"CentOS 4.8",
SEARCH("CentOS 5.8",[OS],"CentOS 5.8",
SEARCH("CentOS 6.0",[OS],"CentOS 6.0",
SEARCH("CentOS 6.10",[OS],"CentOS 6.10",
"(unknown)"
)
This is where I get the error message. Thank you!