The following examples illustrate complex formula user-defined fields using conditional expressions.
Example 1
If ([Creation Date] > Date(2009; 7; 9); "New"; "Old")
This example compares a date field with a constant date; using the Date function to format the date properly. The formula returns an alphanumeric value. If the date is later than the supplied date; the field has a value of “New”. If the date is earlier than the supplied date; the field has a value of “Old”.
Example 2
If(Not(Search("Canada";[Country])>0 Or Search("USA";[Country])>0 Or Search(“Mexico”;[Country])>0);"Other";"North America")
This example inspects the Country field of an Address Book entry to determine if the entry is located in North America or not. It uses the alphanumeric Search function to look for the countries “Canada”; “USA”; or “Mexico”. If none of those strings are found in the entry’s Country field; the formula evaluates to “Other”; but if one of those strings is found it outputs “North America”.
Example 3
If (Dayofweek([Creation Date]) == 1; "Sunday";
If (Dayofweek([Creation Date]) == 2; "Monday";
If (Dayofweek([Creation Date]) == 3; "Tuesday";
If (Dayofweek([Creation Date]) == 4; "Wednesday";
If (Dayofweek([Creation Date]) == 5; "Thursday";
If (Dayofweek([Creation Date]) == 6; "Friday";
If (Dayofweek([Creation Date]) == 7; "Saturday"; " ")))))))
This example uses the Dayofweek function to get the day of the week expressed as an integer value for a date field. It compares the value with integer values and outputs a string representing the day of the week in. If it does not have a value; it outputs an empty string.