1 Reply Latest reply on Jan 2, 2020 3:59 AM by John James

    IN Operator alternative

    aditya tomar

      Hi ,


      Is there any alternative to IN operator which is used in sql.I tried using IN or any function. but it does not work.


      Only way i can do it is:


      IF [Category]='Furniture' or [Category]='Technology'

      THEN [Sales] ELSE 0



      which becomes cumbersome for mutliple values.


      Another method 2:


      IF contains("Furniture,Technology",

      [Category])=true THEN [Sales] ELSE 0



      Another method 3:


      CASE [Category] WHEN "Furniture" THEN [Sales]

      WHEN "Technology" THEN [Sales] ELSE 0 END


      Please let me know if there is any other method ..

        • 1. Re: IN Operator alternative
          John James

          Hi Aditya,


          The CONTAINS function is the most robust option outside of STARTSWITH and ENDSWITH. I know the methods you've given are generic examples but they can be shortened a little:


          CONTAINS("Furniture,Technology", [Category])


          Because it's a boolean, Tableau Desktop adds the if/else logic automatically.


          As a rule of thumb, if you can't find a function in the product manual, it's a safe assumption it's not a feature of Tableau Desktop. There are a few exceptions but there are very few of these and they are usually detailed in the community or on partner pages.