4 Replies Latest reply on Aug 3, 2016 6:10 AM by ryan otto

    How to get around error with IF or CASE statement

    ryan otto

      hello! i am still new to tableau and having trouble with the case and if statements. i am basically trying to write them like SQL and it isn't working.

       

      what i have in the IF statement is:

       

      IF [Region] = "China" AND ISNULL([Contract Number]) THEN [Region] ELSE "N/A" END

       

      so bascially, i have some fields and if the record is from china and there is NOT a number in the [Contract Number] Field then i want the record to be viewable/countable/etc. Otherwise, it can be returned as N/A and filtered out.

       

      the error i am getting is: Expected type string, found integer. Results types from 'IF' expressions must match.

       

      so i try the CASE statement:

       

      CASE [Region] WHEN [Region] = "CHINA" AND ISNULL([Contract Number]) THEN [Region] ELSE "N/A" END

       

      and i receive the error: Expected type string, found boolean. Comparison in 'CASE' expression must be string type.

       

      this is BEYOND annoying since i can code this out in SQL in 10 seconds but cannot see why this does not work. I have looked for a CONVERT function but cannot find it.

      any help is appreciated.