8 Replies Latest reply on Mar 3, 2017 11:34 AM by Jim Powell

    IF statement with multiple value condition

    Jurien Groot

      What would be the easiest way to make a calculation with a random group of orderid's?

       

      Say we have orderid 1,2,3,4,5,6

       

      I want something like:

      IF orderid = 1 OR 4 OR 6 THEN 1

      ELSEIF orderid = 2 OR 3 OR 5 THEN 2

      END

        • 1. Re: IF statement with multiple value condition
          Tracy Rodgers

          Hi Jurien,

           

          The formula would look similar to the following:

           

          if [orderid]=1 or [orderid]=4 or [orderid]=6 then 1

          elseif [orderid]=2 or [orderid]=3 or [orderid]=5 then 2

          end

           

          Hope this helps!

           

          -Tracy

          2 of 2 people found this helpful
          • 2. Re: IF statement with multiple value condition
            Jurien Groot

            Hi Tracy,

             

            It's quite a long list of orderid's. Isn't there a nicer / cleaner way to work with parameters, groups or sets?

             

            Thanks though!

            • 3. Re: IF statement with multiple value condition
              Romil Shah

              Hi Jurien,

               

              Did you find nicer way to group or categorize multiple order id's using sets or groups or mapping table or something else?

               

              I am also looking for similar requirement.

               

              Group Name Owner Name
              ADMIN Michael Stiltner
              ADS Database Mark Rylko
              ADS Deployment Michael Stiltner
              Application Support-Knowledge Review Michael Stiltner
              BDS Dev Level 3 Michael Stiltner
              Clarity Michael Stiltner
              Common Services Mark Rylko
              CreditRetriever Dev Level 3 Michael Stiltner
              CR Internet Michael Stiltner
              CRS3 PRODUCTION SUPPORT Michael Stiltner
              CRS Batch Michael Stiltner
              CRS CFMS Michael Stiltner
              CRS Online Michael Stiltner
              CTSG Michael Stiltner
              DB2 Engineering Distributed Mark Rylko

               

              Above snapshot contains only few entries.There are 450 such rows. Hence it would be very tedious to maintain 450 line of code.

               

              Hence, I feel there should be a nicer way of coding it..

               

              Below is code snippet I used....

               

              case [Group Name]

              When "EAS Level 1" THEN "Rlyko"

              When "Web Hosting" THEN "Rlyko"

              WHEN "Siteminder" THEN "Rlyko"

              WHEN "EOC-NETWORK" THEN "Stiltner"

              WHEN "UFO Level 3" THEN "Stiltner"

              case [Group Name]
              When "EAS Level 1" THEN "Roesel"
              When "Web Hosting" THEN "Roesel"
              WHEN "Siteminder" THEN "Roesel"
              WHEN "EOC-NETWORK" THEN "Stiltner"
              WHEN "UFO Level 3" THEN "Stiltner"

              .............................

              .........

               

               

              Regards,

              Romil

              • 4. Re: IF statement with multiple value condition
                david henington

                Yes, something that allows for multiple values instead of logically grouping each record and then not allowing it to be grouped again. IF THEN OR instead of IF THEN ELSE.

                1 of 1 people found this helpful
                • 5. Re: IF statement with multiple value condition
                  Tableau kumar

                  Hi,

                   

                  If [Region] ="Central" or [Region] ="East" then "Territory1"

                  elseif [Region] ="Nothr" or [Region] ="South" then "Territory2"

                  else "Territory1" end

                   

                  I hope the above syntax help your situation.

                   

                  For additional Information on "How to write Conditions in Tableau";

                  Writing Conditions in Tableau

                   

                  Best Regards

                  Laxman Kumar

                  2 of 2 people found this helpful
                  • 6. Re: IF statement with multiple value condition
                    Animesh Raut

                    You may use Grouping of the data and create the specific groups. I suppose this will be bit more efficient than writing condition. Else if there is a pattern(like odd numbers in 1 group and even number in another than try Calculated field). Also see bins if the size of the bins/category are pre defined @

                     

                     

                    • 7. Re: IF statement with multiple value condition
                      Pawel Jancz

                      Was having similar issue today and I've sorted it with:

                       

                      IF CONTAINS("EAS Level 1, Web Hosting, Siteminder", [Group Name]) then "Rlyko"

                      ELSEIF CONTAINS("EOC-NETWORK, UFO Level 3", [Group Name]) then "Stiltner"

                      ......

                      END

                       

                      It's still quite fixed/manual sollution but works well for me.

                       

                      Hope this helps

                      4 of 5 people found this helpful
                      • 8. Re: IF statement with multiple value condition
                        Jim Powell

                        How did this work? Maybe this just doesn't work with Sets. I was trying to compare a Dimension against a custom Set but it gives me the following error:

                        CONTAINS is being called with (string,boolean), did you mean (sting, string)?