6 Replies Latest reply on Jul 12, 2018 11:59 AM by Michael Prokop

    CASE Statement with "Between"

    Sara Bradberry

      I need to essentially create bins for one of my measures but since the measure is a calculated field, from what I understand and can see you cannot bin a calculated field.

       

      My calculated field essentially just calculates a percentage and I need to use this number to create a bar chart that indicates what % of my total population falls in each bin, ie, 10 people are between 0 and 20% complete, 15 people are between 21 and 40%, etc.

       

      I had been attempting to use the following calculation but cant find anything on how to get it to work correctly.  Tableau is giving me the error "Expected 'THEN' to match 'CASE'"

       

      CASE [Total Completed] WHEN between 0 AND 20 THEN "0-20%"

      CASE [Total Completed] WHEN between 21 AND 40 THEN "21-40%"

      CASE [Total Completed] WHEN between 41 AND 60 THEN "41-60%"

      CASE [Total Completed] WHEN between 61 AND 80 THEN "61-80%"

      CASE [Total Completed] WHEN between 81 AND 100 THEN "81-100%"

      ELSE 0

      END