Conditional logic in formula fields
Key Takeaway
IF tests one condition and returns one of two values, while CASE compares one expression to a list of values. Reference a picklist value only with ISPICKVAL, CASE or TEXT, because comparing a picklist with = or != causes an error.
Conditional logic lets a formula field return different results depending on a record's data. You build it mainly with IF and CASE, fed by functions that return TRUE or FALSE, such as AND, ISBLANK and ISPICKVAL.
IF: test one condition
IF tests one condition, the logical_test, and returns one of two values:
IF(logical_test, value_if_true, value_if_false)value_if_true and value_if_false must be the same data type.
For example, a Days Open formula on Case can use this IF:
IF(ISBLANK(ClosedDate),
TODAY() - DATEVALUE(CreatedDate),
DATEVALUE(ClosedDate) - DATEVALUE(CreatedDate))Open cases have no ClosedDate, so they count up to today. Closed cases count up to the close date.
For more than two outcomes, you can nest IF functions by placing another IF in the value_if_false slot.
For example, a default value formula on a custom percent field can set a tax rate. The formula checks $User.City against one city after another and returns null if none match.