7 Replies Latest reply on Oct 11, 2016 10:08 AM by matt.lukoff.0

# Help with an if/then formula for a field

Hello,

Can anyone help with a formula to create a string field in tableau for this logical statement

Three ID Fields:

ID1

ID2

ID3

Use ID1 except if

ID1 is null than use ID2.

If ID2 is null than ID3.

If all three are null than keep as null

Thanks!

• ###### 1. Re: Help with an if/then formula for a field

Have you tried this calcuation -

IF ISNULL([ID1]) THEN [ID2]

ELSEIF ISNULL([ID2]) THEN [ID3]

ELSEIF ISNULL([ID3]) THEN NULL

END

• ###### 2. Re: Help with an if/then formula for a field

Hi Matt! You can do it Shelby's way, or you can also use the IFNULL() function.

IFNULL([ID1], IFNULL([ID2], [ID3]))

• ###### 3. Re: Help with an if/then formula for a field

Shelby Lovejoy and @David LI thank you however both ways seem to be ignoring what I really want by default which is ID1. I only want to use this function if ID1 is Null but otherwise I want to show ID1.

• ###### 4. Re: Help with an if/then formula for a field

IF NOT ISNULL([ID1]) THEN [ID1]

ELSEIF ISNULL( [ID1]) THEN [ID2]

ELSEIF ISNULL([ID2]) THEN [ID3]

ELSEIF ISNULL([ID3]) THEN NULL

END

1 of 1 people found this helpful
• ###### 5. Re: Help with an if/then formula for a field

Did you try to use the calculation? It should work. IFNULL(X, Y) will return X if X is not null. If it is null, it will return Y.

• ###### 6. Re: Help with an if/then formula for a field

You might want to double check your raw data.

There were times when I expected something to return as NULL but it returned as blank in my data set.