8 Replies Latest reply on Oct 4, 2013 6:42 AM by Natalie Woo

# IF ELSE question

I am trying to fix this :

IF [@PY Rate] = "NA" THEN "NA"

ELSE

STR(({@CY Rate} - INT({@PY DART Rate})) / INT({@PY Rate})*100)

but an error display and i cannot fix this.

The error said on this statement    IF [@PY Rate] = "NA" THEN "NA"'

"cannot compare string and float values"

• ###### 1. Re: IF ELSE question

What does the error say?

I assume the error is because you cannot compare a string and an integer in a calc.  You may also need to wrap the first part in an ATTR() and the rates in a SUM() so all fields are aggregates.

• ###### 2. Re: IF ELSE question

I tried that but it said expected type string, found integer. result from IF must match ..

• ###### 3. Re: IF ELSE question

This will be a lot easier if you can post a sample/mock up workbook that demonstrates the problem.  Without seeing the data, its hard to verify what is going on.

IF attr([@PY Rate]) = "NA" THEN "NA"

ELSE

STR((int({@CY Rate}) - INT({@PY DART Rate})) / INT({@PY Rate})*100)

END

Something like the above, should work, I believe.  I didn't watch my parentheses closely, though.

• ###### 4. Re: Re: IF ELSE question

Hello Mathew,

Please see the attached file, I cannot fix the two calculation errors till... thank you for helping.

• ###### 5. Re: IF ELSE question

"NA" does not appear to be a valid result of  [@PY Rate], so I'm not sure I understand what you are trying to do.  The result of  [@PY Rate] is going to be a decimal value (Float), which is why you're receiving the error.

On the other calculation, you have two values separated by commas in your SUM argument.  I'm not sure what you're trying to do there, either.

• ###### 6. Re: Re: IF ELSE question

Thank you Mathew, now I understand why the first formula is not working. I am sorry I do not setup the formulas, I am transfering the formula from Crystal and tableau and sometimes I do not know what are the meaning behind the formula.

On the other calculation,

Sum([1DC],[MAIN GROUPING])/(Sum([@PYDH],[SUB GROUPING])/200000)

If i want to sum of [1DC] in the "Main grouping" group then divided by the Sum of [@PYDH] in the "Sub Grouping" Group. How should I write the formula?

In Crystal, we use [equation],group name] to to so, I am not sure how to do it in Tableau. Thank you

• ###### 7. Re: IF ELSE question

I may not be the best person to answer that; I am not sure what your best approach would be.  I'll let someone else try to help with that as I am coming up blank.

• ###### 8. Re: Re: IF ELSE question

Thank you very much Mathew for all your help, I really appreciated for your time.