5 Replies Latest reply on Sep 2, 2018 10:18 AM by Shinichiro Murakami

# mix if and iif statement

Hi I am using tableau desktop 2018.2 and need some help with creating a calculated field mixing if & iif statements, I tried it in excel which makes sense and is correct but unable to reproduce the same in tableau.

I am trying to compare the two percentages, A & B both will be at least 0%, and I need to write a if statement to check which is bigger. Now here is the catch, I want to have 3 conditions rather than the normal 2. First I want to check if A is greater than B and I want to check if both are non-zero,  and are the same, and third if they happen to be 0%, I want results to display 0% and else, B is better.

Now syntax below is from excel and I just need to replace it with syntax in tableau but I can't get it to work.  Again, both % will be at least 0% but I want to separate 0% from the condition if A=B and when both non 0%.

=IF(A1>B1,"A is better",IF(AND(A1<>0,B1<>0,A1=B1),"Same",IF(AND(A1=0,B1=0),"0%","B is better")))

• ###### 1. Re: mix if and iif statement

Please attach sample data as twbx format.

Thanks,

Shin

• ###### 2. Re: mix if and iif statement

I have just attached a sample data.

Thanks

• ###### 3. Re: mix if and iif statement

I recommend that you add sequential ID at least in database.

Anyways, translated Tableau's syntax is

IF [A %]>[B%] then "A is better"

elseif [A %]<>0 and [B%]<>0 and [A %]=[B%] then "Same"

elseif [A %]=0 and [B%]=0 then "0%"

else "B is better"

end

Thanks,

Shin

2 of 2 people found this helpful
• ###### 4. Re: mix if and iif statement

Thank you for your help it works just the way I want it. Thank you again.

• ###### 5. Re: mix if and iif statement

Hi John

You are very welcome.

Shin