7 Replies Latest reply on Aug 16, 2019 3:00 AM by Weronika Walczak

    How to create two filters using an OR operator

    Adnan Irshad

      Hello-

       

      I have a dashboard which is filtered on vendor number but the client is asking for vendor name too as the filter. They will use the vendor number but if they don't know the number then they can use vendor name filter. When I try to bring in the vendor name filter, it uses an and clause and filters on the vendor number and the name. I want to use just one of them at a time, either the vendor number filter or the name.

       

      Thanks in advance.

      Adnan.

        • 1. Re: How to create two filters using an OR operator
          James Colvin

          The most straightforward solution would be to add a new Calculated field that concatenates these two fields into a single field, and use that as your filter.

           

          I don't have v9 of Tableau installed to be able to upload a workbook you can open, but it could be as simple as:

           

          // Vendor Filter

          [Vendor Name] + " : " + STR([Vendor Number])

           

          You need the STR() argument to turn the integer into a string (text) so you can combine the two fields.

           

          When you drag that into the filter shelf, your users can now search by either name or number to find the vendor they'd like to filter by.

          1 of 1 people found this helpful
          • 2. Re: How to create two filters using an OR operator
            Joe Oppelt

            Tableau will just do "AND" logic on quick filters.

             

            You can make your own "OR" calc that would looks something like this:

             

             

                      IF <whatever constitutes condition 1> OR <whatever constitutes condition 2> THEN 1 ELSE 0 END

             

             

            Then you put that calc on the filter shelf and select for value = 1.

             

            But the real question is how you collect your user's input to condition-1 and/or condition-2.

             

            You could have two parameters.  One is a list of vendor names.  The other a list of vendor numbers.  Let you user select from those, and then for condition-1, for example, you would do:

             

                      ... [Vendor Name] = [Vendor Name Parameter] ...

             

            Still, I see problems here.  What do you do if the user has one selection for Vendor Name, and another for Vendor Number?  You could end up gathering two vendors on your sheet.  You could prevent that by popping out an error sheet that covers your data viz if there are conflicting selections.  "You cannot have a selected value in both "Vendor Name" and "Vendor Number"."  (Something like that.)  Provide a "none" option in each parameter.  One or the other needs to be set to "none".

             

            All this is just thinking out loud.  Maybe it will trigger the idea you need to handle this requirement.

            • 3. Re: How to create two filters using an OR operator
              Joe Oppelt

              I like that, James.  Wildcard match on the filter.

              • 4. Re: How to create two filters using an OR operator
                Lisa Li

                Hey Adnan,

                 

                This post: CoEnterprise | Blog - Playing with Parameters Part I: Extending Search Logic  also describes how to extend search logic and give users opportunity to search and filter data on a variety of dimensions.

                 

                -Lisa

                CoEnterprise | Home

                • 5. Re: How to create two filters using an OR operator
                  Adnan Irshad

                  Thank you so much James!

                   

                  Your solution worked for me. This was the first topic I posted on Tableau and thank you for the quick turnaround. I was told that Tableau community is awesome and I completely agree with that.

                   

                  Thank you all!

                  • 6. Re: How to create two filters using an OR operator
                    Tom W

                    Adnan,

                    Please mark the answer as correct to close the thread

                    • 7. Re: How to create two filters using an OR operator
                      Weronika Walczak

                      Hi Adnan,

                      I have another solution for you - with using Parameter.

                       

                      1. Create the parameter:

                      vendor_1.PNG

                       

                      2. Create the calculated field where you use this parameter:

                      vendor_2.PNG

                      3. Show your parameter control and show this calculated field as filter. Use 'wildcard match' for filter 'enter vendor data'. Now you can choose the parameter (vendor number or vendor name) and then enter known data.

                      vendor_3.PNG

                      vendor_3a.png

                       

                       

                      4. By default, if 'enter your data' field is empty, you'll see all vendors on the screen.

                      vendor_4.PNG

                       

                       

                      If you want see nothing when this filter is empty, let change it by editing filter:

                      vendor_5.PNG

                       

                      I hope this will be useful.

                      Greetings!

                      Weronika