12 Replies Latest reply on Sep 13, 2018 5:03 PM by Manuel Ramos

# Expected END to Match IF at character 0

Hello Tableau Community!

Can someone help me fix this Calculated Field?

CASE [Case Distributions, Backlog & Closures Picker]

WHEN 1 THEN [Assigned to CSR GMT] >= DATE([DATEADD('hour',7,NOW())])

WHEN 2 THEN DATE([Assigned to CSR GMT]) = DATE([DATEADD('hour',7,NOW())])-1

WHEN 3 THEN IF DATEPART('year',[Assigned to CSR GMT]) = DATEPART('year',TODAY())THEN

DATEPART('week',[Assigned to CSR GMT]) = DATEPART('week',TODAY())

WHEN 4 THEN IF DATEPART('year',[CLOSEDDATE_GMT]) = DATEPART('year',TODAY())THEN

DATEPART('week',[CLOSEDDATE_GMT]) = DATEPART('week',TODAY())

WHEN 5 THEN STR([CLOSEDDATE_GMT]) = NULL

END

• ###### 1. Re: Expected END to Match IF at character 0

Hi

I think the issue is in the first line

you have an inequality that needs to an = sign

Jim

If this posts assists in resolving the question, please mark it helpful or as the 'correct answer' if it resolves the question. This will help other users find the same answer/resolution.  Thank you.

• ###### 2. Re: Expected END to Match IF at character 0

Problem is with '[' and ']' , please replace them with paranthesis '(' and ')'

>= actually works fine

1 of 1 people found this helpful
• ###### 3. Re: Expected END to Match IF at character 0

Thank you, Jim.  For taking the time to review and respond with a suggestion.  I tried, but Tableau returned the same error message.   If you have another suggestion I'd be happy to try it.  Thanks!

• ###### 4. Re: Expected END to Match IF at character 0

Hi Anisha...thank you for your response.  I just tried replacing the square bracket you pointed out from WHEN 1 and WHEN 2 scenarios with parenthesis but received the same error message.

After making the change from square brackets to parenthesis I realized I now had extra parenthesis in the WHEN 1 and WHEN 2 scenarios so I removed then, but even still received the same error message.

Even though the adjustments did not work, I am going to keep my edits of removing the square brackets for now, as think that change is getting closer to a valid calculation.

Please let me know if you have any other suggestions.  Thanks again.

• ###### 5. Re: Expected END to Match IF at character 0

You need to put 'END' keyword on the blank highlighted rectangles

and also, enclose the IF-THEN-END structure in paranthesis for readability

1 of 1 people found this helpful
• ###### 6. Re: Expected END to Match IF at character 0

1 of 1 people found this helpful
• ###### 7. Re: Expected END to Match IF at character 0

Also, please notice that by replacing '[' with '(, color of DATEADD changed to Blue meaning it was identified as a function once you replaced the square brackets.

So i think you need to make both changes that i suggested in my previous posts

1. replace '[' and ']'

2. Add 'END' keyword as highlighted

1 of 1 people found this helpful
• ###### 8. Re: Expected END to Match IF at character 0

Hi Anisha ... I tried making both changes that you suggested as described below, but now received a different error message:  "Expected type string, found integer.  Comparison in 'CASE' expression must be a string type."

1. Replaced '[' and ']' with '(' and ')' in the WHEN 1 and WHEN 2 scenarios , but then deleted the  '(' and ')' because of extra/unnecessary parenthesis.

2. Added 'END' keyword as highlighted

3. Enclosed the IF-THEN-END structures in the WHEN 3 AND WHEN 4 scenarios in parenthesis for readability.

Is there anything else you can suggest I can try?

• ###### 9. Re: Expected END to Match IF at character 0
1 of 1 people found this helpful
• ###### 10. Re: Expected END to Match IF at character 0

The structure of CASE is CASE, WHEN...THEN, END.

The structure of IF is IF, THEN, ELSE (optional), END.

You can 1x CASE and 2x IF but only 1x END

So as Tableau reads your case, it doesn't understand where the CASE and IF's should end because they're not balanced.

1 of 1 people found this helpful
• ###### 11. Re: Expected END to Match IF at character 0

Please consider marking the replies as Correct/Helpful as appropriate to close the thread. This helps anyone who may be looking for a solution to a similar problem.

Thanks!

• ###### 12. Re: Expected END to Match IF at character 0

Thanks very much, Anisha!