Syntax error while calculating fields using ifelse() condition

I’m working on creating a column to identify whether an entry should be labeled as a defect or not. I’ve attempted the following calculation but encountered a syntax error. Could someone please provide guidance?

ifelse(
    ({jobstatus} = 'COMPLETED' AND {hintstate} = 'SUCCESS' AND ({smeanswer} = 'Success' OR {smeanswer} = 'NOT_SURE') AND {primary_bin_value} = {binid}),
    'No Defect',
    ifelse(
        ({jobstatus} = 'COMPLETED' AND {hintstate} = 'SUCCESS' AND ({smeanswer} = 'Success' OR {smeanswer} = 'Not sure') AND {primary_bin_value} = {binid}),
        'No Defect',
        ifelse(
            ({jobstatus} = 'COMPLETED' AND {hintstate} = 'MULTIPLE_EVENTS' AND {smeanswer} = 'Multiple Events' AND ({primary_bin_value} = {binid} OR isnull({primary_bin_value})) AND {secondary_bin_value} = {secondarybinid}),
            'No Defect',
            ifelse(
                ({jobstatus} = 'COMPLETED' AND ({hintstate} = 'NO_EVENT' OR {hintstate} = 'OTHER') AND {smeanswer} = 'No event'),
                'No Defect',
                'Defect'
            )
        )
    )
)

Hi @isingla,
Looking at your expression, it seems like the error could come from comparing incompatible data types. For example if you try to compare a String field with a field of type Integer, it will result in a syntax error. Do you see a particular part of your expression being highlighted (with a red line under the expression)? You should start by looking at the data types of the left and right side of that specific comparison first and then ensure to compare compatible data types.

Did this answer your question? If so, please help the community out by marking this answer as "Solution!

Hi Thomas,

I made some modifications to the logic:

ifelse(
    {jobstatus} = 'COMPLETED' AND {hintstate} = 'SUCCESS' AND (contains({smeanswer}, 'Success') OR contains({smeanswer}, 'NOT_SURE')) AND contains({smeanswer}, {binid}),
    'No Defect',
    ifelse(
        {jobstatus} = 'COMPLETED' AND {hintstate} = 'NOT_SURE' AND (contains({smeanswer}, 'Success') OR contains({smeanswer}, 'Not sure')) AND contains({smeanswer}, {binid}),
        'No Defect',
        ifelse(
            {jobstatus} = 'COMPLETED' AND {hintstate} = 'MULTIPLE_EVENTS' AND contains({smeanswer}, 'Multiple Events') AND (contains({smeanswer}, {binid}) OR isNull({smeanswer})) AND contains({smeanswer}, {secondarybinid}),
            'No Defect',
            ifelse(
                {jobstatus} = 'COMPLETED' AND (contains({hintstate}, 'NO_EVENT') OR contains({hintstate}, 'OTHER')) AND contains({smeanswer}, 'No event'),
                '0',
                '1'
            )
        )
    )
)

Please note all the columns are of strings datatype. But I am still getting an error as below:

At least one of the arguments in this function does not have correct type.

This time, the issue is caused by the way you are using the contains function, as the editor should also highlight at contains({smeanswer}, {binid}). The second argument (substring) needs to be a String that does not have any dependency to any field. Only the first argument (expression) can be derived from a field.

Hope this helps to understand where the error is coming from.

Did this answer your question? If so, please help the community out by marking this answer as "Solution!