7 Replies Latest reply on Mar 27, 2012 9:58 AM by Jonathan Drummey

# If statements

I would like to do the following logic statement...

If a number is <10 then "10 Days Wait"

If a number is between 3 and 10  then "3-10 Days Wait"

If a number is >3 then " 1-3 Days Wait"

If number = 0 then "No Wait"

Can anyone help with the logic in Tableau to create this?

Thanks!

• ###### 1. Re: If statements

You had <10 when I assume you meant >10 and >3 when I assume you meant <3, based on the labels you provided. Here's a calc:

If [field] > 10 Then ">10 Days Wait"

Elseif [field] > 3 Then "3 - 10 Days Wait"

Elseif [field] > 0 Then "1 - 3 Days Wait"

Elseif [field] = 0 Then "0 Days Wait"

End

You could change the last Elseif to an Else if you know the only remaining values are 0. When I'm working with data that I don't know I like to be explicit about the values I expect and then leave room in the calculation for unexpected values, for example what would you want to display if there were -1 days? In that case, the calc as I wrote it will return Null and you'll have a chance to see that in your results.

Jonathan

• ###### 2. Re: If statements

Thanks Jonathan! If a want the Nulls to be a catagory as well would it be...

Elseif "Null" then "No Show"

END

• ###### 3. Re: If statements

You wouldn't use quotes around the Null. Quotes around text indicate the value is a string, so "Null" is different from Null.

Jonathan

• ###### 4. Re: If statements

Thanks!

How would you add the logic for something like

If a negative number then "Error"

If a blank "" then "No Show"

• ###### 5. Re: If statements

You'd just tack on some more ELSEIF's. One question, though - is the field blank "" or Null? If it's Null, then you don't use =, you use the ISNULL() function, which returns binary True if the field is Null.

ELSEIF [field] <0  THEN "Error"
ELSEIF "" THEN "No Show"

ELSEIF ISNULL([field]) THEN "field is Null"

Jonathan

• ###### 6. Re: If statements

it's a blank field in excel with no value, so i assume i use the ELSEIF ISNULL([field]) THEN "field is Null"

• ###### 7. Re: If statements

It's probably Null, you'll have to load your data and find out whether it's really Null or "" (an empty string).