8 Replies Latest reply on Jun 20, 2019 7:17 AM by Ken Flerlage

    Comma separated filter

    Dylan Wood

      Long-time viewer, first time poster.

       

      I am attempting to create a filter based off a single column that can contain different comma-separated strings for each row. There are ~250 various strings that the column can contain so splitting this column isn't an ideal solution and the strings can be in different order for each row.

       

      Example:

      Recipe NumberDescriptionIngredients
      1Baked Chickensalt, butter, milk, cayenne pepper, corn, bread crumbs
      2Chilicorn - frozen, cinnamon, garlic, milk
      3French Toastmilk, eggs, butter, cinnamon

       

      Given this is pretty basic, I want to be able to filter recipes via checkboxes using distinct ingredients.

       

      Problem: the If elseif isn't capturing all the ingredients listed and is basically ending after Milk is seen. Is there a way to parse the entire cell for every value individually rather than stopping after the 'milk' calculation is met?

       

      Calculation used:

      IF  CONTAINS([Ingredients],LOWER('Cinnamon')) THEN 'Cinnamon'

      ELSEIF CONTAINS([Ingredients],LOWER('Milk')) THEN 'Milk'

      ELSEIF CONTAINS([Ingredients],LOWER('salt')) THEN 'salt'

      ELSEIF CONTAINS([Ingredients],LOWER('egg')) THEN 'egg'

      ELSEIF CONTAINS([Ingredients],LOWER('butter')) THEN 'butter'

      ELSEIF CONTAINS([Ingredients],LOWER('cayenne pepper')) THEN 'cayenne pepper'

      ELSEIF CONTAINS([Ingredients],LOWER('corn')) THEN 'corn'

      ELSEIF CONTAINS([Ingredients],LOWER('bread crumbs')) THEN 'bread crumbs'

      END

        • 1. Re: Comma separated filter
          Ken Flerlage

          You're trying to generate a list of potential values for the filter. I get that, but it won't work like this. The IF statement will stop as soon as a criteria is met. So, between your 3 records, all of them contain either cinnamon or milk, so one of the first two criterion is met and the if statement stops. In order to get individual values, you are going to need to have a data set large enough where you can guarantee that at least criteria is met at least once. But, even if you did that, this isn't going to work as you expect it to. Each row will only have one value for "Ingredients Filter" and that will be the first criteria it meets. For example, Chill will meet the Cinnamon criteria only so that will only have one value.

          To make this work, you're going to need to break out each ingredient into a separate record. So, for example, French Toast will have four records--1 for each of the ingredients. If, by some chance, nothing has more than 10 ingredients, then you could use Tableau Prep to split the values then do a Pivot step. Here's how to do that: https://interworks.com/blog/kwagner/2018/12/27/split-and-pivot-your-data-with-tableau-prep/

          • 2. Re: Comma separated filter
            Rodrigo Calloni

            Hi Dylan

             

            I have a very similar use case and you could use a parameter in combination with a CONTAINS check to achieve your filtering.

             

            So first create a simple String parameter and leave it empty.

             

            Then Create a calculated field like this:

             

            CONTAINS(LOWER([Ingredients]),LOWER([Paramater]))

             

            To finish, place the calculated field in the Filter shelf and pick TRUE.

             

            Now show your paramater. If an user types MILK, tableau will retrieve the 3 records you want. If they type Salt, then only first row will show up.

             

            Note: this solution is similar to creating a Wildcard filter, but I find it to me more resource efficient.

             

            Keep vizzing
            Rodrig

            • 3. Re: Comma separated filter
              Ken Flerlage

              This won't allow multi-selecting the options though. You'll only be able to see one component at a time.

              • 4. Re: Comma separated filter
                Dylan Wood

                Thanks Ken.

                 

                Ya I actually tried this after finding it elsewhere, but I need to be select multiple values through a drop down. So once I use my actual data, I can allow my users to pick and choose (mix and match) which ingredients they want to see recipes for.

                • 5. Re: Comma separated filter
                  Dylan Wood

                  Thanks Ken,

                   

                  Is there a different method entirely that could recommend?

                  • 6. Re: Comma separated filter
                    Rodrigo Calloni

                    Yes Ken is right (as always), you can't multi-select with this solution.

                     

                    Rodrigo

                    • 7. Re: Comma separated filter
                      Peter Fakan

                      Hi Dylan,

                       

                      Just thinking aloud picking up on your different method entirely comment, have you thought about having each ingredient as a column and then maybe have a series of parameters that just do the equivalent of a true/false display on it ?

                       

                      i.e. I'm thinking of maybe 5 parameters where you select Milk, eggs, sugar, maple syrup and flour and the list will filter itself down to pancakes.

                       

                      HTH

                       

                      Peter

                      • 8. Re: Comma separated filter
                        Ken Flerlage

                        I'd recommend having each ingredient on its own row.