2 Replies Latest reply on Jan 17, 2017 9:21 AM by Jamieson Christian

    How to dynamically filter by T/F boolean dimensions ?

    Thomas Karbe

      I have multiple True/False boolean dimensions. Each boolean field, when added to the filter shelf and when true is selected, successfully limits the view to the time period specified by the boolean.  The dimensions are Last Month(T/F), This Month(T/F), Last Week(T/F), This Week(T/F), Yesterday (T/F). What I would like is that the user of the dashboard can choose the dimension.

       

      So far I have tried this with Parameters. A Time_Unit period parameter which specifies 'Months', 'Weeks', or 'Days' and another parameter with value 'previous' or 'current'. I wanted the user to choose for example 'Months' and 'previous' and have a calculated field choose the 'Last Month'(T/F) dimension. Below was my attempt

       

      Attempt:

      IF (time_unit) = 'Months' AND (current_or_previous) = 'previous' Then (Last Month)

      ELSEIF (time_unit) = 'Months' AND (current_or_previous) = 'current Then (This Month)

      ELSEIF (time_unit) = 'Weeks' AND  (current_or_previous) = 'current' Then (This Week)

      ...

       

      The problem is that a calculated field with an IF statement cannot result in a boolean.

       

      My next thought was to add all Dimensions to the filter shelf and have the user just tick true for the dimension he would like to filter by. However, I do not know how to turn a filter 'off'. Filters on 'false' would already filter the view.

       

      My goal: Have the user able to choose the boolean dimension he would like to filter by, either through parameters or turning them 'on' and 'off' on the filter shelf.

       

      Any help is very much appreciated.

        • 1. Re: How to dynamically filter by T/F boolean dimensions ?
          Joe Oppelt

          Thomas Karbe wrote:

           

          ...

           

          The problem is that a calculated field with an IF statement cannot result in a boolean.

           

           

           

           

          I always use 1/0 instead of Boolean.  It's just a personal preference.  So I never encountered the fact that an IF can't result in a Boolean.

           

          Don't let that limitation stop you.  Just make your results be 1 or 0 instead of TRUE or FALSE, and run with that.


          I didn't open the workbook.  I just wanted to add this to the discussion.

           

          What Tableau version is your workbook, if I need to go there?

          1 of 1 people found this helpful
          • 2. Re: How to dynamically filter by T/F boolean dimensions ?
            Jamieson Christian

            Thomas,

             

            Since your filter calcs are Boolean, just rewrite the parameter-driven filter to do straight Boolean algebra instead of an IF statement.

             

            [Selected filter]

               ([Time_Unit] = 'Months' AND [Current or Previous Time Period?] = 'previous' AND [Last Month ])
            OR ([Time_Unit] = 'Months' AND [Current or Previous Time Period?] = 'current'  AND [This Month ])
            OR ([Time_Unit] = 'Weeks' AND  [Current or Previous Time Period?] = 'current'  AND [This week ])

             

             

            (I didn't attach a sample workbook because there's not enough data in the sample to even illustrate how this works. Try it on your full data set.)