Returns the results of an either/or conditional evaluation. If the initial argument evaluates as TRUE
, returns the result of evaluating the second argument; otherwise, returns the result of evaluating the third argument.
Sample usage
IF(TRUE, "Yes!", "No!")
returns Yes!
IF(FALSE, "Yes!", "No!")
returns No!
IF((1 > 0), "Yes!", "No!")
returns Yes!
IF((1 < 0), "Yes!", "No!")
returns No!
IF(ISBLANK(""), "Yes!", "No!")
returns Yes!
See also: ISBLANK().
IF(NOT(ISBLANK("")), "Yes!", "No!")
: No!
Equivalent to IF(ISNOTBLANK(""), "Yes!", "No!")
. See also: ISNOTBLANK()
, NOT()
.
IF(([Count] < 0), 0, [Count])
returns 0
if the Count
column value is less than zero, or the value itself if zero or greater. Equivalent to MAX(LIST(0, [Count]))
. See also: LIST()
, MAX()
.
IF(([Date] = TODAY()), TRUE, FALSE)
: Returns TRUE
if the Date
column value matches today's date; otherwise, returns FALSE
. Equivalent to ([Date] = TODAY())
. See also: TODAY()
.
IF(USERSETTINGS("Names in uppercase?"), UPPER([Name]), [Name])
returns the Name
column in all uppercase letters if the value of the Names in uppercase?
user setting is TRUE
; otherwise, returns the Name
column value unchanged. See also: UPPER()
, USERSETTINGS()
.
IF(ISNOTBLANK([Phone Number]), [Phone Number], "(no phone)")
returns the column value if the Phone Number
column value isn't blank; otherwise, returns the text (no phone)
.
IF(ISNOTBLANK([Customer].[Discount Rate]), ([Price] * [Customer].[Discount Rate]), [Price])
: If the customer has a discount, the discounted price is returned; otherwise, the original price is returned.
Leap year?
IF(
(
MONTH(
DATE(
"2/28/"
& YEAR(TODAY())
)
+ 1
)
= 2
),
"leap year",
"not leap year"
)
TODAY()
gives today's date.YEAR(...)
gives the year of the given date."2/28/" & ...
constructs aText
value inMM/DD/YYYY
-format date for February 28 of this year.DATE(...)
declares the constructedText
value aDate
value.DATE(...) + 1
adds one day to the given date.MONTH(...)
gives the month number of the computed date,1
to12
, where1
is January and12
is December.((...) = 2)
asks whether the month number is2
(February).IF(..., "leap year", "not leap year")
givesleap year
if the day after February 28 of this year is in February, ornot leap year
if not.
See also: DATE()
, MONTH()
, TODAY()
, YEAR()
.
Weekday or weekend?
IF(
IN(
WEEKDAY(TODAY()),
LIST(1, 7)
),
"It's the weekend!",
"It's a weekday."
)
TODAY()
gives today's date.WEEKDAY(...)
gives the weekday number of the given date,1
to 7, where1
is Sunday and7
is Saturday.LIST(1, 7)
constructs a list of two numbers:1
and7
.IN(..., ...)
asks whether the computed weekday number is present in the constructed list.IF(..., "It's the weekend!", "It's a weekday.")
givesIt's the weekend!
if the the weekday number is1
or7
, orIt's a weekday.
otherwise.
See also: IN()
, LIST()
, TODAY()
, WEEKDAY()
.
Syntax
IF(logical-expression, value-if-true, value-if-false)
logical-expression
- AYes/No
expression that evaluates toTRUE
orFALSE
.value-if-true
- An expression to be evaluated only if thelogical-expression
evaluates asTRUE
.value-if-false
- An expression to be evaluated only if thelogical-expression
evaluates asFALSE
.
Both value-if-true
and value-if-false
should produce results of comparable types (for example, both textual, or both numeric). The results may both be single values or lists.