ECMA-376 5th edition Part 1 (December 2016) section 18.17.7 defines seven logical functions: AND, FALSE, IF, IFERROR, NOT, OR and TRUE (the category table of 18.17.7 lists exactly these). This page gives each one’s syntax, arguments, return value and worked examples as the standard states them, then [MS-OI29500] v20260818’s notes on what Office does differently, then the result LibreOffice gives for each example. The Formulas page has the grammar these functions are written with; the math functions page has the numeric ones. In a cell a function is its upper-case name followed by the arguments in parentheses, separated by commas.
How the examples were checked
Every worked example of the standard, and some edge cases, were put in a flat ODS workbook of 35
formulas and converted to CSV by LibreOffice (soffice --headless --convert-to csv; files
samples/xlsx/oracle/logicalfn/logical-functions.fods and .csv in the project). The examples that
name cells (E6, F6, A3, B3) were given those cell values on a second sheet. LibreOffice is an
implementation, not the standard: where it differs from the standard or from Excel’s notes the
difference is reported, not corrected. The viewer reads a formula and shows the value stored in the
cell; it calculates only inside conditional-format rules (cf.js, see the last section).
AND (18.17.7.9)
AND ( argument-list ): tests whether all arguments are TRUE; every argument is evaluated
before the value is returned.
| Argument | Type | Meaning |
|---|---|---|
argument-list | logical, array or cell reference | The values to test. In an array or a cell reference, a cell that holds text or is empty is ignored. |
Returns a logical: TRUE if all arguments are TRUE, otherwise FALSE. If no logical values are found, #VALUE!. [MS-OI29500] has no note on AND.
| Standard’s example | Standard says | LibreOffice |
|---|---|---|
AND(TRUE) | TRUE | TRUE |
AND(TRUE,FALSE) | FALSE | FALSE |
AND(10>5,3=1+2,5) | TRUE | TRUE |
AND({10,5,6,7},TRUE,E6:F6), E6 = TRUE, F6 = 10 | TRUE | TRUE |
Edge: AND(C1), C1 holds the text “text” | #VALUE! (no logical value found) | #VALUE! |
Edge: AND(1,"a") | not stated (a text literal, not a reference) | #VALUE! |
OR (18.17.7.246)
OR ( argument-list ): tests whether any one or more arguments are TRUE; every argument is
evaluated.
| Argument | Type | Meaning |
|---|---|---|
argument-list | logical, array, reference | The values to test. In an array or a cell reference, a cell that holds text or is empty is ignored. |
Returns a logical: TRUE if any argument is TRUE, otherwise FALSE. If no logical values are found, the standard says the return value is unspecified (unlike AND, which gives #VALUE!). [MS-OI29500] has no note on OR.
| Standard’s example | Standard says | LibreOffice |
|---|---|---|
OR(TRUE) | TRUE | TRUE |
OR(FALSE,FALSE) | FALSE | FALSE |
OR(10=5,3=1+2,0) | TRUE | TRUE |
OR({10,5,6,7},TRUE,E6:F6), E6 = FALSE, F6 = 0 | TRUE | TRUE |
Edge: OR(C1), C1 holds text | unspecified | #VALUE! |
NOT (18.17.7.233)
NOT ( logical-value ): the logical negation of its argument.
| Argument | Type | Meaning |
|---|---|---|
logical-value | logical | The value to negate. |
Returns a logical: TRUE if the argument is FALSE and FALSE if it is TRUE. [MS-OI29500] has no note on NOT.
| Standard’s example | Standard says | LibreOffice |
|---|---|---|
NOT(TRUE) | FALSE | FALSE |
NOT(FALSE) | TRUE | TRUE |
NOT(10>5) | FALSE | FALSE |
NOT(16.567) | FALSE (a non-zero number counts as TRUE) | FALSE |
Edge: NOT(0) | not stated | TRUE |
Edge: NOT("a") | not stated | #VALUE! |
TRUE (18.17.7.331) and FALSE (18.17.7.117)
TRUE ( ) and FALSE ( ) take no arguments and return the logical values TRUE and
FALSE. A call is equivalent to the logical constant of the same name in the formula grammar (see
Formulas). [MS-OI29500] has no note on either.
| Standard’s example | Standard says | LibreOffice |
|---|---|---|
TRUE() | TRUE | TRUE |
FALSE() | FALSE | FALSE |
A numbering slip in the standard. The category table (before 18.17.7.1) gives TRUE as §18.17.7.330, but the clause is 18.17.7.331 (18.17.7.330 is TRIMMEAN), as the table of contents and the heading say. This page uses 18.17.7.331.
IF (18.17.7.147)
IF ( logical-value , [ value-if-true ] [ , [ value-if-false ] ] ): tests the first argument;
if it is TRUE the second is evaluated and returned, otherwise the third.
| Argument | Type | Meaning |
|---|---|---|
logical-value | logical | The value to test. |
value-if-true | any | Returned when logical-value is TRUE. If omitted it evaluates to 0. May contain up to seven levels of nested IF calls. It need not have the same type as value-if-false. |
value-if-false | any | Returned when logical-value is FALSE. If it and its preceding comma are omitted, the result is FALSE; if it is omitted but the comma is present, the result is 0. May contain at least seven levels of nested IF calls. |
Returns the value of value-if-true or value-if-false (any type). If an argument is an array, every element of the array is evaluated when the argument is evaluated.
Excel note (MS-OI29500 2.1.963): the standard limits nesting of the two value arguments to seven levels; Office allows as many levels as the application allows.
| Standard’s example | Standard says | LibreOffice |
|---|---|---|
IF(10>5,"Yes","No") | Yes | Yes |
IF(10>5,"Yes") | Yes | Yes |
IF(10>5,"Yes",) | Yes | Yes |
IF(10<5,"Yes") | FALSE | FALSE |
IF(10<5,"Yes",) | 0 | 0 |
IF(10>5,,"No") | 0 | 0 |
IF(10>5,,) | 0 | 0 |
IF(10>5,"Yes",20) | Yes | Yes |
IF(10<5,"Yes",20) | 20 | 20 |
Edge: IF("a",1,2) | not stated (the argument is declared logical) | #VALUE! |
Edge: IF(2,"t","f") | not stated | t (a non-zero number is TRUE) |
IFERROR (18.17.7.148)
IFERROR ( value , value-if-error ): returns the first argument unless it is an error, in
which case it returns the second; it replaces the older pattern of testing a value for an error and then
computing it again.
| Argument | Type | Meaning |
|---|---|---|
value | any | The value checked for an error. The standard lists #N/A, #VALUE!, #REF!, #DIV/0!, #NUM!, #NAME? and #NULL!. An empty cell is treated as an empty string. |
value-if-error | any | Returned when value is an error. An empty cell is treated as an empty string. |
Returns value if it is not an error, otherwise value-if-error. If value is an array formula, an array of results for each cell of the range in value is returned.
Excel note (MS-OI29500 2.1.964): besides the seven errors above, Office also checks for #GETTING_DATA.
| Standard’s example | Standard says | LibreOffice |
|---|---|---|
A3/B3, A3 = 55, B3 = 0 | #DIV/0 (the standard omits the “!”) | #DIV/0! |
IFERROR(A3/B3,"Error in calculation") | Error in calculation | Error in calculation |
Edge: IFERROR(NA(),"x") | x (#N/A is listed) | x |
Edge: IFERROR(A4,"e"), A4 empty | the empty cell is treated as an empty string | 0 (the empty cell is a number 0, not an empty string) |
Edge: IFERROR(1/0,A4), A4 empty | the empty cell is treated as an empty string | 0 |
Divergence. For an empty cell as value or value-if-error the standard says an empty string results; LibreOffice returns the number 0. This page does not say which one Excel returns, because [MS-OI29500] has no note on it and no Excel was run.
What the viewer does
The viewer shows the value a cell stores and never recalculates a worksheet. Its conditional-format
rules (explorer/formats/xlsx/cf.js) do evaluate all seven functions of this page. The IF
cases and the text-argument differences below are run against the results above in
test-xlsx-built.mjs; the rules for text inside a range, and for IFERROR, are code readings:
- AND and OR: booleans and numbers count, text in a range is ignored, a text literal outside a range
counts as FALSE where LibreOffice gives #VALUE! (
AND(1,"a")), and no countable value gives #VALUE! (agrees with the standard for AND, and with LibreOffice for OR). - NOT and IF: a text argument counts as FALSE, where LibreOffice gives #VALUE!
(
NOT("a"),IF("a",1,2)). - IF: an omitted value-if-true gives 0, and an omitted value-if-false gives 0 when its comma is present and FALSE when it is not, as the standard states (changed in this round; before it an omitted value-if-true gave TRUE and an empty argument made the rule not calculated).
- IFERROR: returns value-if-error for any of the error values the viewer knows; the empty-cell rule of the standard is not applied.
See also
- Formulas: the grammar, logical constants, error values and limits
- Functions: math
- Cells: how a formula is stored in a cell
Not described on this page
- Excel’s own results for the examples: only [MS-OI29500] was read; Excel was not run, so the last column is LibreOffice, not Excel.
- The other functions of 18.17.7 (text, date and time, lookup, statistical, financial, engineering, database, information, cube, web, and the math functions outside the math page). Functions that Excel added after the standard, such as IFS, IFNA, SWITCH and XOR, are not in Part 1 or in the [MS-OI29500] notes searched, and are not described here.
Sources
- ECMA-376 5th edition Part 1, research/ooxml/ecma376/p1/part1.txt: category table (line 77027), 18.17.7.9 AND (line 77641), .117 FALSE (81964), .147 IF (82950), .148 IFERROR (82990), .233 NOT (85577), .246 OR (86452), .331 TRUE (89228)
- [MS-OI29500] v20260818, research/ooxml/ms/MS-OI29500.txt, notes 2.1.963 and 2.1.964 (lines 19035 to 19043)
- LibreOffice, soffice headless, flat ODS to CSV: samples/xlsx/oracle/logicalfn/