1 Reply Latest reply on Nov 11, 2016 1:06 PM by Nathan Panuco

    Cannot use 'boolean' type in 'if' experssion

    Matthew Risley

      I'm getting contradicting errors. Tableau may need to change their wording on the errors. (pictures below).


      I have a business need where users want a single dashboard where they can have: (1) all data up to the date they pick or

                                                                                                                                           (2) Just data for the month of the date they pick


      I created a parameter Called [Time Value] and even the T|F calculations to filter the view.


      I'd like for the users to pick from the [Time Value] parameter so that the date they pick, using the [Filter by Date], parameter will be accurate. i

      Example: User picks 10/31/16 from [Filter by Date]  and "Up to this date" from  [Time Value]. it should show all the data up until 10/31/16. If they picked the other option, it would only show October 2016 data.


      Here is the calculation I'd like to use:


      if [Time Value] = "up to this date"

          then ["Up to this date" filter]

      ELSEIF [Time Value] = "this month only"

          then ["Just this Month" Filter]



      Simply put, if the parameter is one thing, do a certain calculation - if it is the other thing, perform the other calculation.

      How would one do this?


      I get this error.


      Side note (maybe something Tableau needs to work on?)

      But what baffles me beyond belief is that I received this error after I thought I solved this error. Just seems like hard to follow wording?:


      The second picture states that comparisons must be booleans, then the first picture says cannot use boolean in the if expression.

        • 1. Re: Cannot use 'boolean' type in 'if' experssion
          Nathan Panuco

          Hi Matthew!


          Your calculation looks accurate, but in the first screenshot, there is an error because ["up to this date" filter] and ["just this month" filter] fields are boolean and cannot be used in that manner. However, you are encountering a separate but similar error in screenshot #2. In that screenshot, there is an error because in IF statements, the first comparison must result in a boolean expression and the calculation there is an IF then has a string. If "up to this date" is not a valid expression.


          I was able to avoid getting the error (using the same calculation) just by changing the ["up to this date" filter] and ["just this month" filter] to strings. Howver, after looking at how those are calculated, they will also likely need modification to achieve your desired results. You may want to add another IF statement into those fields like IF MONTH([Filter By Date]) >= MONTH([Document Date]) then "True" else "False".






          Hope this helps!

          1 of 1 people found this helpful