Bug 152774 - MATCH and HLOOKUP/VLOOKUP return incorrect result when searching for a string in a mixed numeric/string matrix
Summary: MATCH and HLOOKUP/VLOOKUP return incorrect result when searching for a string...
Status: RESOLVED FIXED
Alias: None
Product: LibreOffice
Classification: Unclassified
Component: Calc (show other bugs)
Version:
(earliest affected)
Inherited From OOo
Hardware: All All
: medium normal
Assignee: Winfried Donkers
URL:
Whiteboard: target:7.6.0 target:7.5.1
Keywords:
Depends on:
Blocks: Calc-Function
  Show dependency treegraph
 
Reported: 2022-12-31 13:58 UTC by Winfried Donkers
Modified: 2023-01-16 15:18 UTC (History)
3 users (show)

See Also:
Crash report or crash signature:


Attachments
Sample test file (10.15 KB, application/vnd.oasis.opendocument.spreadsheet)
2023-01-01 13:22 UTC, m_a_riosv
Details

Note You need to log in before you can comment on or make changes to this bug.
Description Winfried Donkers 2022-12-31 13:58:45 UTC
Description:
=MATCH("a";{1;3;"b";"d"};1) returns 2 but should return #N/A.

ODF, 6.14.9 MATCH says for "MatchType = 1 or omitted" that "If Search is of type Text and the value found is of type Number, the #N/A Error is returned."

Steps to Reproduce:
Enter 
=MATCH("a";{1;3;"b";"d"};1) 
in any cell in Calc.

Actual Results:
2

Expected Results:
#N/A


Reproducible: Always


User Profile Reset: No

Additional Info:
ODF, 6.14.9 MATCH says for "MatchType = 1 or omitted" that "If Search is of type Text and the value found is of type Number, the #N/A Error is returned."
Comment 1 m_a_riosv 2022-12-31 20:35:07 UTC
Hi @Winfried, I think you forget to set up properly the last parameter, must be 0 to find the exact value. With 0 returns #N/A.
Comment 2 Winfried Donkers 2023-01-01 09:26:12 UTC
(In reply to m.a.riosv from comment #1)
> Hi @Winfried, I think you forget to set up properly the last parameter, must
> be 0 to find the exact value. With 0 returns #N/A.

The last parameter is set properly (range sorted and ascending, first equal or  less closest to search parameter matching)
I am not looking for an exact value, but for the best match equal or less than the search value in a sorted (ascending) range.
There is no exact match "a" in {1;3;"b";"d"} and according to the sorting conventions in ODF 3 is the best natch less than "a".
However, because of the special case as mentioned in ODF 6.14.9 (search of type text and value found of type number) not 3, but #N/A is to be returned.
Comment 3 m_a_riosv 2023-01-01 13:22:49 UTC
Created attachment 184418 [details]
Sample test file

(In reply to Winfried Donkers from comment #2)
> ....
> There is no exact match "a" in {1;3;"b";"d"} and according to the sorting
> conventions in ODF 3 is the best natch less than "a".
> However, because of the special case as mentioned in ODF 6.14.9 (search of
> type text and value found of type number) not 3, but #N/A is to be returned.

Sorry for my misleading.

After a little test, seems it works as you have commented with ranges, but fails with an inner array.
Comment 4 GerardF 2023-01-01 20:23:03 UTC
Excel returns #N/A if you need to know.
Comment 5 Commit Notification 2023-01-12 14:55:56 UTC
Winfried Donkers committed a patch related to this issue.
It has been pushed to "master":

https://git.libreoffice.org/core/commit/0ce4c1e6898ba83d487f1b225dc9ee0bbc00d9fc

tdf#152774 Fix incorrect result with MATCH.

It will be available in 7.6.0.

The patch should be included in the daily builds available at
https://dev-builds.libreoffice.org/daily/ in the next 24-48 hours. More
information about daily builds can be found at:
https://wiki.documentfoundation.org/Testing_Daily_Builds

Affected users are encouraged to test the fix and report feedback.
Comment 6 ady 2023-01-13 23:07:04 UTC
FWIW, doing:

=MATCH("a";{1;3;"b";"d"};1)

also results in "2" in portable Apache OpenOffice 4.1.13 on Windows 10.

AOO4113m1(Build:9810)  -  Rev. 281f0d3533
2022-07-01 10:22

In LO 7.4.4.2, saving the file as xlsx and then opening it in excel (365), the same cell will result in "#N/A" (as already commented above).
Comment 7 Commit Notification 2023-01-15 16:03:14 UTC
Winfried Donkers committed a patch related to this issue.
It has been pushed to "master":

https://git.libreoffice.org/core/commit/bf432958c1d6d204511a6bb32e2c06161d811676

tdf#152774 Fix incorrect result with HLOOKUP and VLOOKUP.

It will be available in 7.6.0.

The patch should be included in the daily builds available at
https://dev-builds.libreoffice.org/daily/ in the next 24-48 hours. More
information about daily builds can be found at:
https://wiki.documentfoundation.org/Testing_Daily_Builds

Affected users are encouraged to test the fix and report feedback.
Comment 8 Commit Notification 2023-01-16 08:40:30 UTC
Winfried Donkers committed a patch related to this issue.
It has been pushed to "libreoffice-7-5":

https://git.libreoffice.org/core/commit/a5103adc413fb2cc8811c8691de5bfbe2df51961

tdf#152774 Fix incorrect result with MATCH, HLOOKUP and VLOOKUP.

It will be available in 7.5.1.

The patch should be included in the daily builds available at
https://dev-builds.libreoffice.org/daily/ in the next 24-48 hours. More
information about daily builds can be found at:
https://wiki.documentfoundation.org/Testing_Daily_Builds

Affected users are encouraged to test the fix and report feedback.