diff --git a/CHANGELOG.md b/CHANGELOG.md index 3131df955..fd75713f3 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -26,6 +26,7 @@ The format is based on [Keep a Changelog](https://keepachangelog.com/en/1.0.0/), - **Breaking change**: Changed the license from GPLv3 to a proprietary license. HyperFormula is no longer available under GPLv3; see [`LICENSE.txt`](LICENSE.txt) for the new terms. Versions 3.x and earlier remain available under GPLv3. [#1885](https://github.com/handsontable/hyperformula/pull/1885) - **Breaking change**: Added the `#CALC!` error, which `FILTER` and `UNIQUE` now return instead of `#N/A` when the result would be an empty array, `SEQUENCE` returns instead of `#VALUE!` when the number of rows or columns truncates to 0 (e.g. `=SEQUENCE(0)`), and `CONCAT` and `TEXTJOIN` return instead of `#VALUE!` when the result is longer than 32,767 characters, as in Microsoft Excel. `IFNA()` and `ISNA()` no longer catch these errors; use `IFERROR()` or `ISERROR()`. A custom language pack must now translate the `CALC` error, or `registerLanguage()` throws a `MissingTranslationError`. See the [migration guide](https://hyperformula.handsontable.com/docs/guide/migration-from-3.x-to-4.0.html). [#1647](https://github.com/handsontable/hyperformula/issues/1647) - **Breaking change**: Changed the `INDEX` function to match Microsoft Excel. A row or column past the range now returns `#REF!` instead of `#NUM!`, a fractional row or column is truncated, and a row or column of `0` returns the whole column or row, which spills. Without a column number, `INDEX` returns `#REF!` for a range with more than one row and column instead of using its first column, returns the whole row of an array with more than one row and column, and counts along a one-row range. `INDEX` also accepts the `area_num` argument. See the [migration guide](https://hyperformula.handsontable.com/docs/guide/migration-from-3.x-to-4.0.html). [#1544](https://github.com/handsontable/hyperformula/issues/1544) +- **Breaking change**: Changed the `FILTER` function to return `#VALUE!` for text in its `include` argument, including the empty text and `"TRUE"`, and to return an error found there, as in Microsoft Excel. Before, it dropped those rows, or kept them for `"TRUE"`. For example, a condition column of `=IF(B1>0, TRUE(), "")` now makes `FILTER` return `#VALUE!`; return `FALSE()` instead of `""`. See the [migration guide](https://hyperformula.handsontable.com/docs/guide/migration-from-3.x-to-4.0.html). [#1891](https://github.com/handsontable/hyperformula/pull/1891) ### Fixed diff --git a/docs/guide/migration-from-3.x-to-4.0.md b/docs/guide/migration-from-3.x-to-4.0.md index 36c361d27..5ebbe620f 100644 --- a/docs/guide/migration-from-3.x-to-4.0.md +++ b/docs/guide/migration-from-3.x-to-4.0.md @@ -9,6 +9,7 @@ tags: - "#CALC!" - language packs - INDEX + - FILTER --- To upgrade your HyperFormula version from 3.x.x to 4.0.0, follow this guide. @@ -60,3 +61,17 @@ HyperFormula 4.0 changes the `INDEX` function to return what Microsoft Excel ret | The `area_num` argument | `=INDEX(A1:C3, 1, 1, 1)` | `#N/A` (wrong number of arguments) | The value of `A1` | A spilled result needs empty cells to spill into, or it returns `#SPILL!`. If your code checks for `ErrorType.NUM` from `INDEX`, check for `ErrorType.REF` instead. + +## The `FILTER` function + +HyperFormula 4.0 reads the `include` argument of `FILTER`, its second argument, as Microsoft Excel does. Text in it returns `#VALUE!`, and an error in it is returned: + +| Value in `include` | 3.x | 4.0 | +|:-------------------|:----|:----| +| `TRUE`, a non-zero number | The row is kept | The row is kept | +| `FALSE`, `0`, a blank cell | The row is dropped | The row is dropped | +| Text, such as `"x"` or the empty text `""` | The row is dropped | `#VALUE!` | +| The text `"TRUE"` | The row is kept | `#VALUE!` | +| An error, such as `#DIV/0!` | The row is dropped | The error | + +If a condition column can hold text, for example `=IF(B1>0, TRUE(), "")`, return `FALSE()` instead of `""`. Conditions after `include`, which HyperFormula accepts in addition to Excel, still drop such rows. diff --git a/hyperformula/src/interpreter/plugin/ArrayPlugin.ts b/hyperformula/src/interpreter/plugin/ArrayPlugin.ts index 68047aa18..0fa1ba761 100644 --- a/hyperformula/src/interpreter/plugin/ArrayPlugin.ts +++ b/hyperformula/src/interpreter/plugin/ArrayPlugin.ts @@ -371,8 +371,18 @@ export class ArrayPlugin extends FunctionPlugin implements FunctionPluginTypeche const row = [] for (let j = 0; j < rangeVals.width(); j++) { let ok = true - for (const filter of rangeFilters) { - const val = coerceScalarToBoolean(filter.data[i][j]) + for (let k = 0; k < rangeFilters.length; k++) { + const condition = rangeFilters[k].data[i][j] + // The first condition is Excel's `include`: text in it, even "TRUE", which coerceScalarToBoolean would + // accept, returns #VALUE!, and an error in it is returned. Further conditions are HyperFormula's own + // extension and keep dropping such rows. + if (k === 0 && typeof condition === 'string') { + return new CellError(ErrorType.VALUE, ErrorMessage.WrongType) + } + const val = coerceScalarToBoolean(condition) + if (k === 0 && val instanceof CellError) { + return val + } if (val !== true) { ok = false break