Difference between revisions of "Documentation/How Tos/Calc: IF function"
From Apache OpenOffice Wiki
< Documentation | How Tos
(Initial content) |
m |
||
Line 3: | Line 3: | ||
== IF == | == IF == | ||
Returns one of two values, depending on a test condition. | Returns one of two values, depending on a test condition. | ||
− | |||
=== Syntax: === | === Syntax: === | ||
Line 14: | Line 13: | ||
If <tt>'''value2'''</tt> is omitted it is assumed to be <tt>'''FALSE'''</tt>; if <tt>'''value1'''</tt> is also omitted it is assumed to be <tt>'''TRUE'''</tt>. | If <tt>'''value2'''</tt> is omitted it is assumed to be <tt>'''FALSE'''</tt>; if <tt>'''value1'''</tt> is also omitted it is assumed to be <tt>'''TRUE'''</tt>. | ||
− | |||
=== Example: === | === Example: === | ||
Line 23: | Line 21: | ||
<tt>'''IF(2>1)'''</tt> | <tt>'''IF(2>1)'''</tt> | ||
: returns <tt>'''TRUE'''</tt> - because both <tt>'''value1'''</tt> and <tt>'''value2'''</tt> have been omitted and 2 is more than 1. | : returns <tt>'''TRUE'''</tt> - because both <tt>'''value1'''</tt> and <tt>'''value2'''</tt> have been omitted and 2 is more than 1. | ||
− | |||
=== See also: === | === See also: === |
Revision as of 17:20, 25 January 2008
IF
Returns one of two values, depending on a test condition.
Syntax:
IF(test; value1; value2) where:
- test is or refers to a logical value or expression that returns a logical value (TRUE or FALSE).
- value1 is the value that is returned by the function if test yields TRUE.
- value2 is the value that is returned by the function if test yields FALSE.
If value2 is omitted it is assumed to be FALSE; if value1 is also omitted it is assumed to be TRUE.
Example:
IF(A1>5;100;"too small")
- returns the number 100 if A1 is greater than 5, and the text "too small" otherwise.
IF(1>2;"nonsense")
- returns FALSE - because value2 has been omitted and 1 is not greater than 2.
IF(2>1)
- returns TRUE - because both value1 and value2 have been omitted and 2 is more than 1.