Bug 163592 - Sort function breaks and shows err504 with a single row as a result
Summary: Sort function breaks and shows err504 with a single row as a result
Status: RESOLVED FIXED
Alias: None
Product: LibreOffice
Classification: Unclassified
Component: Calc (show other bugs)
Version:
(earliest affected)
24.8.2.1 release
Hardware: x86-64 (AMD64) Linux (All)
: medium minor
Assignee: Balázs Varga (allotropia)
URL:
Whiteboard: target:25.8.0 target:25.2.2 target:24...
Keywords:
Depends on:
Blocks: Cell-Formula
  Show dependency treegraph
 
Reported: 2024-10-23 15:59 UTC by dominykas.bucinskas
Modified: 2025-03-04 09:10 UTC (History)
5 users (show)

See Also:
Crash report or crash signature:


Attachments
test document to see the error. (36.30 KB, application/vnd.oasis.opendocument.spreadsheet)
2024-10-23 15:59 UTC, dominykas.bucinskas
Details
Simplified example (20.08 KB, application/vnd.oasis.opendocument.spreadsheet)
2024-10-25 15:25 UTC, Wolfgang Jäger
Details

Note You need to log in before you can comment on or make changes to this bug.
Description dominykas.bucinskas 2024-10-23 15:59:05 UTC
Description:
I have this function on my sheet:

SORT(FILTER(CHOOSE({1.2};$'Master log of records'.$B$5:$B$10033;$'Master log of records'.$A$5:$A$10033);$'Master log of records'.$B$5:$B$10033=B29;"NULL");2;-1)

It works fine, when FILTER results in at least two and more rows, but when that underlying FILTER table results in only 1 entry, it returns err504. I tested that with excel and it works fine there. It is really strange. It works normally if I use:

=CONCATENATE("QF-004-002"; " / "; RIGHT(IFNA(VLOOKUP(B30;SORT(FILTER(CHOOSE({1.2};$'Master log of records'.$B$5:$B$10045;$'Master log of records'.$A$5:$A$10045);$'Master log of records'.$B$5:$B$10045=B30;{"NULL";"NULL"});2;-1);2;FALSE());" ");3))

i.e. two-dimensional array for "result if empty" parameter.

version 24.8.2.1

Thanks a lot.

Steps to Reproduce:
Please, use the complex function described in description section. See attached file.

Actual Results:
err504 with that function. I will attach file for ease of testing as it is difficult to describe input and results.

Expected Results:
I expect not err504, but correctly formatted string.


Reproducible: Always


User Profile Reset: No

Additional Info:
I have attached the file. First sheet, first column, you can see variable results of this evaluation.
Regarding attached file: Idea is to display on first sheet, first column: document_number / last_number_used, i.e. like QF-004-001 / 002. That simply means that QF-004-001 is just a number of template and all derivatives are numbered with suffix like QF-004-001-001, QF-004-001-002 etc. Second sheet has all them (derivatives) listed. So I would like to have last no used on the first sheet next to the base document name. I do that by concatenating multiple strings of document number itself and then doing filtered (with swapped columns), sorted vlookup. This result is used with right function to get required symbols, i.e. end number of document.

Forum suggested answer here: https://ask.libreoffice.org/t/sort-function-breaks-and-shows-err504-with-a-single-row-as-a-result/112713
Comment 1 dominykas.bucinskas 2024-10-23 15:59:47 UTC
Created attachment 197206 [details]
test document to see the error.
Comment 2 dominykas.bucinskas 2024-10-23 16:08:47 UTC
I double checked, but 

=CONCATENATE("QF-004-002"; " / "; RIGHT(IFNA(VLOOKUP(B30;SORT(FILTER(CHOOSE({1.2};$'Master log of records'.$B$5:$B$10045;$'Master log of records'.$A$5:$A$10045);$'Master log of records'.$B$5:$B$10045=B30;{"NULL";"NULL"});2;-1);2;FALSE());" ");3)) 

Also does not work. I was wrong. It produced incorrect result.
Comment 3 Wolfgang Jäger 2024-10-25 15:25:57 UTC
Created attachment 197239 [details]
Simplified example

The given example and the contained formula are (imo) by far too complex to clearly show the bug.
Therefore I attach a simplified example also containing the case that SORTBY() is used.
Comment 4 Commit Notification 2025-02-27 15:03:57 UTC
Balazs Varga committed a patch related to this issue.
It has been pushed to "master":

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

tdf#163592 - sc fix Sort/SortBy function shows err504 instead of results

It will be available in 25.8.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 5 Commit Notification 2025-02-27 19:16:44 UTC
Balazs Varga committed a patch related to this issue.
It has been pushed to "libreoffice-25-2":

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

tdf#163592 - sc fix Sort/SortBy function shows err504 instead of results

It will be available in 25.2.2.

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 Commit Notification 2025-03-04 09:10:44 UTC
Balazs Varga committed a patch related to this issue.
It has been pushed to "libreoffice-24-8":

https://git.libreoffice.org/core/commit/574ee6527e1d1c3ef08bc0bbe91bbc2673a3b8e6

tdf#163592 - sc fix Sort/SortBy function shows err504 instead of results

It will be available in 24.8.6.

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.