4 Replies Latest reply on Nov 28, 2016 11:12 PM by Glenn Kuly

    Conditional Subsetting

    Glenn Kuly

      Hello, I'm stumped by something that I believe should be easy to accomplish, conditional filtering using a calculated field.

       

      I'm trying to visualize distributions of various demographic characteristics (gender, age, etc) broken down by membership in various groups. This is a (very) Q&S representation of the sort of dataset I'm using:

      image 1.png

      My dashboard has bar charts for gender, age range, etc,, and I've set up a calculated field so that users can filter the distributions by various groups, but I'm getting some funky results, and can't figure out why. Here is my calculated field:

       

      CASE [Parameters].[Classify]

      WHEN "Plumber" THEN FLOAT([Occupation] = "Plumber")

      WHEN "Employed" THEN FLOAT([Job Status] = "Employed")

      END

       

      The results are fine for the first group (Occupation = Plumber is my example), but the numbers displayed for the second group are off:

       

      image 2.png

      I can't figure out what is going wrong here, much less how to fix it. I've also tried using a parameter for my groups, but I cannot figure out how to use conditional subsetting with the CASE function.

       

      -- Glenn

        • 1. Re: Conditional Subsetting
          Tom W

          Hi Glenn,

          Can you upload a Tableau Packaged Workbook including your work to date instead of the Excel attachment?

           

          Thanks!

          • 2. Re: Conditional Subsetting
            Glenn Kuly

            Hi Tom, uploading the test workbook.

             

            I get why my approach is not working, the first group (plumbers in my example) is being captured correctly in the first IF-THEN statement, but only the 'uncaptured' records are showing up under other groups targeted in subsequent ELSEIF-THEN statements.

             

            I could solve the problem by creating derived variables in my dataset, but I want to avoid this, and do all my calculations inside Tableau.

             

            -- Glenn

            • 3. Re: Conditional Subsetting
              Glenn Kuly

              I just watched a Tableau training video which gave me a solution.

               

              For each group by which I want to subset the distributions of the various demographic characteristics, I can create the following calculated field:

               

              If [Job Status] = "Employed" THEN 1 ELSE NULL END

               

              Then I can create a parameter and calculated field to choose among my subset groups, and show (according to my test example) the gender distribution for plumbers, for persons who are employed, etc.

               

              image 3.png

              The attached test example isn't great, but this is going to be very useful filtering technique.

               

              -- Glenn