4 Replies Latest reply on Jul 13, 2018 8:55 AM by suman kumar

# Error "Cannot mix aggregate and non-aggregate comparisons or results in 'IF' expressions

Hi,

I’m new to Tableau and am slowly getting to grips with it. I am trying to calculate efficiency for the current year using the below mentioned calculated field but it is throwing an error of aggregate and non-aggregate comparisons which kind of makes sense so I tried putting ATTR in front of  YEAR([Date] but then it returns null. So, I am quite confused.

It would be great if anyone can give me a direction for the same.

PS: Sorry if you found the question silly

IF (YEAR([Date])) = 2018

THEN ([Company LE])

END

• ###### 1. Re: Error "Cannot mix aggregate and non-aggregate comparisons or results in 'IF' expressions

Just Try :

IF (YEAR([Date])) = 2018

THEN {fixed :[Company LE] }

end

1 of 1 people found this helpful
• ###### 2. Re: Error "Cannot mix aggregate and non-aggregate comparisons or results in 'IF' expressions

It's a bit difficult to answer this without understanding your data a bit better and without knowing the definition of "Company LE", but my guess is that "Company LE" is a measure which is already doing some sort of aggregation within its definition. In that case, try something like this:

IF MAX(YEAR([Date])) = 2018

THEN ([Company LE])

END

The Max will be evaluated based on your viz level of detail, which could cause this to go a bit astray. I'd need to see more information or a workbook to be sure.

1 of 1 people found this helpful
• ###### 3. Re: Error "Cannot mix aggregate and non-aggregate comparisons or results in 'IF' expressions

Hey Payal,

Thank you for guiding me in the right direction. Your calculation actually gives me overall efficiency without considering the time period. So, I updated the calcuation with {FIXED YEAR([Date]):([Company LE])} to resolve my issue.

Thank you

• ###### 4. Re: Error "Cannot mix aggregate and non-aggregate comparisons or results in 'IF' expressions

HI,

You have not given ELSE condition what you want if year  is not equal to 2018.

Here I have created one sample. Try like this one.

IF YEAR([Order Date])=2018

THEN [Customer Name]

ELSE NULL

END

Thanks

Suman