8 Replies Latest reply on Nov 28, 2018 1:25 PM by Joe Oppelt

# Expected end to match case at Character 0'

Hello Dear Tableau community,

Upon my research trying to figure out the 'Expected end to match case at Character 0' error....well I gave up, and I am hoping someone has the better knowledge to help me figure out where I did wrong.

Here is my calculation statement, 'Select a Measure' is between count and percentage. And I need the number format to be dynamically displayed also. Count using whole number and Percent is percent with two decimal with a '%' sign.

case [Select a Measure]

WHEN 'Count' then

if attr([Outcome Year]) = 'After Year 1'

then sum([Attrit After Yr 1])

ELSEIF attr([Outcome Year]) = 'After Year 2'

THEN sum([Attrit After Yr 2])

ELSEif attr([Outcome Year]) = 'After Year 3'

THEN sum([Attrit After Yr 3])

END

WHEN 'Percent' then

If attr([Outcome Year]) = 'After Year 1'

then STR(ROUND(SUM([Attrit After Yr 1])/TOTAL(SUM([Attrit After Yr 1]))*100,2))

ELSEIF attr([Outcome Year]) = 'After Year 2'

then STR(ROUND(SUM([Attrit After Yr 2])/TOTAL(SUM([Attrit After Yr 2]))*100,2))

ELSEIF attr([Outcome Year]) = 'After Year 3'

then STR(ROUND(SUM([Attrit After Yr 3])/TOTAL(SUM([Attrit After Yr 3]))*100,2))

else null

END

I really don't know where the error is. Thank you guys for your help!!

• ###### 1. Re: Expected end to match case at Character 0'

Just add an END at the bottom.

case [Select a Measure]

WHEN 'Count' then

If attr([Outcome Year]) = 'After Year 1'

then sum([Attrit After Yr 1])

ELSEIF attr([Outcome Year]) = 'After Year 2'

THEN sum([Attrit After Yr 2])

ELSEif attr([Outcome Year]) = 'After Year 3'

THEN sum([Attrit After Yr 3])

END

WHEN 'Percent' then

If attr([Outcome Year]) = 'After Year 1'

then STR(ROUND(SUM([Attrit After Yr 1])/TOTAL(SUM([Attrit After Yr 1]))*100,2))

ELSEIF attr([Outcome Year]) = 'After Year 2'

then STR(ROUND(SUM([Attrit After Yr 2])/TOTAL(SUM([Attrit After Yr 2]))*100,2))

ELSEIF attr([Outcome Year]) = 'After Year 3'

then STR(ROUND(SUM([Attrit After Yr 3])/TOTAL(SUM([Attrit After Yr 3]))*100,2))

else null

END

END

• ###### 2. Re: Expected end to match case at Character 0'

You have the correct END for each IF clause.

You need one more END at the end of it all for the CASE statement itself.

CASE [whatever]

WHEN "X" then "something"

WHEN "y" then "Something Else"
END

• ###### 4. Re: Expected end to match case at Character 0'

You need ENDs after both your IF statements and your CASE.

• ###### 5. Re: Expected end to match case at Character 0'

Can you attach a packaged workbook? I fear there are a few different problems here.

• ###### 6. Re: Expected end to match case at Character 0'

Oh.  in the upper half od the calc you are loading SUM(stuff) and in the bottom half its STR(stuff).

It has to be all numeric or all string.

• ###### 7. Re: Expected end to match case at Character 0'

Thanks Joe! that worked! but since i am using the parameter to swapping the measures, then the number format becomes the issue.

in the percent, it looked ok because i changed the number format to percentage but if i swap back to count, the number is crazy... do you happen to have a way to make the number format dynamic?  • ###### 8. Re: Expected end to match case at Character 0'

I would take the formatting off the axis numbers.  (Just have 20, 40, 60, etc on the percents and 10000, 20000, etc on the big number.)

And if you make everything string in the calc, you can format the string however you want based on the parameter selection.  Just build the % into the overall string right in the calc.

But if you really need the formatting in the axis, then I would look at making two sheets and swap them based on the value of the parameter.  (It's a common technique.  Two sheets occupy the same container, but only one of them displays at a time.)

You can find video examples of how to sheet swap here: