8 Replies Latest reply on Aug 31, 2017 6:43 AM by T G

# Help with creating a calculation field

Hi guys

I do not  know if this can be done in a tableau ,calculation, I have the data below ( this is example data)

 server location 1 location 2 test A north north 1 A west null 2 B west west 1 B north north null

I am trying to create a calculation that will do the  following  - If the server = A and , location 1 and  location 2 are the same then YES, If server=
B and test = 1 than Yes Else no. ( please note The location 1 & 2 will either match or one will be null)

So it should bring back the below

 server location 1 location 2 test A north north 1 B west west 1

Can this be done?

Am I making any sense?

• ###### 1. Re: Help with creating a calculation field

It would be something like this:

If  [server] = 'A' and [location 1] =  [location 2] THEN  'YES'

ELSEIF [server]='B' and test = 1 then 'Yes'

Else 'no'

END

• ###### 2. Re: Help with creating a calculation field

Hello Imran,

Refer the attached workbook. You just need to create calculated field as

IIF(

([Server]='A' AND [Location1]=[Location2])

OR [Server]='B' AND INT([Test])=1,'Yes','No')

• ###### 3. Re: Help with creating a calculation field

thank you , let me just check it

• ###### 4. Re: Help with creating a calculation field

thank you,

what if the I want to say test has 1 anywhere , for example test = 23412 , as long as it has 1 I want it picked up ( like function ), can this be done?

• ###### 5. Re: Help with creating a calculation field

IF Test is String like in first case, you can use this

IIF(

([Server]='A' AND [Location1]=[Location2])

OR [Server]='B' AND CONTAINS([TEST],'1'),'Yes','No')

or else

IIF(

([Server]='A' AND [Location1]=[Location2])

OR [Server]='B' AND CONTAINS(STR([TEST]),'1'),'Yes','No')

• ###### 6. Re: Help with creating a calculation field

Hi ,

Yes the test is a string but its three letters ( before i was using just random made example data sporty).

In this case and I want these 3 letters picked up as long as they are together

e.g find 'abc '  as long  as these three letters appear together I want it pulled back ( in sql you can use like '%abc% don't know if there is a similar function in tableau.

thanks

• ###### 7. Re: Help with creating a calculation field

hI ,

This more or less works but I get 'yes' , 'no' and 'null' to, don't understand why null is coming up

• ###### 8. Re: Help with creating a calculation field

For your like we have CONTAINS function which is already used and this will only work in case of string. In case of int you have to cast it as string using STR function.

About the null, is due to there are some other situations in data which is not included in formula.

I hope now it's clear to you.