Bug 147669 - Calc - MATCH gives wrong result with an inline array
Summary: Calc - MATCH gives wrong result with an inline array
Status: NEW
Alias: None
Product: LibreOffice
Classification: Unclassified
Component: Calc (show other bugs)
Version:
(earliest affected)
7.3.0.3 release
Hardware: All All
: medium normal
Assignee: Not Assigned
URL:
Whiteboard:
Keywords:
Depends on:
Blocks: Cell-Formula
  Show dependency treegraph
 
Reported: 2022-02-26 10:01 UTC by David Lynch
Modified: 2024-06-18 16:55 UTC (History)
5 users (show)

See Also:
Crash report or crash signature:


Attachments
Exhibits bug 147669 (12.19 KB, application/vnd.oasis.opendocument.spreadsheet)
2022-02-26 10:03 UTC, David Lynch
Details

Note You need to log in before you can comment on or make changes to this bug.
Description David Lynch 2022-02-26 10:01:52 UTC
Description:
See attached.
=MATCH("2",{2;3},0) gives #N/A (incorrect)
=MATCH("2",C4:D4,0) gives 1 (correct) if C4=2 and D4=3


Steps to Reproduce:
See attached

Actual Results:
See attached

Expected Results:
See attached


Reproducible: Always


User Profile Reset: No



Additional Info:
I need the first parameter to MATCH be a string because in my application it is a regular expression.
Version: 7.3.0.3 (x64) / LibreOffice Community
Build ID: 0f246aa12d0eee4a0f7adcefbf7c878fc2238db3
CPU threads: 4; OS: Windows 10.0 Build 19044; UI render: Skia/Raster; VCL: win
Locale: en-GB (en_GB); UI: en-GB
Calc: threaded
Comment 1 David Lynch 2022-02-26 10:03:36 UTC
Created attachment 178556 [details]
Exhibits bug 147669
Comment 2 Mike Kaganski 2022-05-08 09:51:50 UTC
Note also, that it works with

=MATCH("2";{"2"|"3"};0)

=> it gives the expected 1.

MATCH with MatchType = 0 is defined in ODFF 1.3 [1] differently compared to MatchType = 1 and MatchType = -1; for the two latter, there's explicit "If Search is of type Text and the value found is of type Number, the #N/A Error is returned", while for the former, no such clause exists, implying that the return value of 1 is really expected here.

[1] https://docs.oasis-open.org/office/OpenDocument/v1.3/OpenDocument-v1.3-part4-formula.html#MATCH
Comment 3 QA Administrators 2024-05-09 03:16:36 UTC Comment hidden (obsolete)
Comment 4 David Lynch 2024-06-16 15:16:20 UTC
Bug present in:

Version: 24.2.4.2 (X86_64) / LibreOffice Community
Build ID: 51a6219feb6075d9a4c46691dcfe0cd9c4fff3c2
CPU threads: 12; OS: Windows 10.0 Build 22631; UI render: Skia/Raster; VCL: win
Locale: en-GB (en_GB); UI: en-GB
Calc: CL threaded
Comment 5 ady 2024-06-16 17:35:23 UTC
Considering that other inline arrays are working with the same MATCH() function, the problem is not exactly the use of inline array, but rather the difference in format (number vs text).

In some sense, it is similar to other reports regarding lookup functions (including MATCH), in which the lookup/search is performed depending on (cell) format, not on (cell) value (and not restricted to inline arrays). See for example tdf#160893.
Comment 6 Eike Rathke 2024-06-18 10:24:02 UTC
MATCH and [HVX]LOOKUP never consider cell format and should not. What happens however is that if the search criterion can be interpreted as a number (which a date string is also) a numeric lookup is performed.
Comment 7 Mike Kaganski 2024-06-18 10:33:10 UTC
(In reply to Mike Kaganski from comment #2)
> MATCH with MatchType = 0 is defined in ODFF 1.3 [1] differently compared to
> MatchType = 1 and MatchType = -1; for the two latter, there's explicit "If
> Search is of type Text and the value found is of type Number, the #N/A Error
> is returned", while for the former, no such clause exists, implying that the
> return value of 1 is really expected here.

I take this back.
The explanations about sorting order in the standard clarify the "If Search is of type Text and the value found is of type Number" clauses in 1/-1 cases: it may happen, that with sorted search, the value *greater than* the numeric Search may happen to be a text after the numeric block. For that, the clauses explain what to do. On the other case, the 0 case is "exact" search, for which, the found value must be equal to the Search - so the clause about different types is not applicable.

So it's up to the settings of the program, not to the standard.
Comment 8 ady 2024-06-18 16:33:08 UTC
(In reply to Mike Kaganski from comment #7)

> So it's up to the settings of the program, not to the standard.

Do you mean settings that can be configured by common users? If yes, which settings?
Comment 9 Mike Kaganski 2024-06-18 16:55:02 UTC
(In reply to ady from comment #8)
> Do you mean settings that can be configured by common users? If yes, which
> settings?

I mean, that the standard does not itself require the behavior wanted here. So it is up to the application, which *may* have settings like Options->Calc->Formula->Detailed Calculation settings->Details->Conversion from text to number; and it's up to the application to either use that setting for this case, or not.

In essence, my comment 7 was to undo the "this is a bug that violates the ODF standard" claim of comment 2.