Bug 164966 - Σ button generates a formula with a wrong range in some cases
Summary: Σ button generates a formula with a wrong range in some cases
Status: NEW
Alias: None
Product: LibreOffice
Classification: Unclassified
Component: Calc (show other bugs)
Version:
(earliest affected)
Inherited From OOo
Hardware: All All
: medium normal
Assignee: Not Assigned
URL:
Whiteboard:
Keywords:
Depends on:
Blocks:
 
Reported: 2025-01-31 06:07 UTC by Yao Fanqing
Modified: 2025-02-03 14:40 UTC (History)
3 users (show)

See Also:
Crash report or crash signature:


Attachments
Adding the sum of the row and the sum of the column will generate an incorrect formula (18.23 KB, application/vnd.oasis.opendocument.spreadsheet)
2025-01-31 06:09 UTC, Yao Fanqing
Details
Example to show range generation bug (45.29 KB, application/vnd.oasis.opendocument.spreadsheet)
2025-02-03 14:18 UTC, Cekomote
Details

Note You need to log in before you can comment on or make changes to this bug.
Description Yao Fanqing 2025-01-31 06:07:44 UTC
Description:
must select sum1 of rows ,sum2 of columns ,blank cell ,3 cells at the same time,use Σ for sum3, then will bug

select d5, e5, and f5 at the same time, and then click the sum function Σ in the menu bar. 
we should get =sum(d5:e5), get 18,but f5  automatically generate =sum(e5:e5) , get 13
if type by hand =d5+e5 will get 18

get  the sum1 of a row  at d5
get the sum2 of a columns at  e5
select 3 cell(d5, e5,f5 ) at the same time,  click menu Σ to sum. 
3 cells, the first cell is the sum of the row, the second cell is the sum of the column, and the third cell is a blank cell
the result will be wrong. it will not include the first cell (sum1) in the calculation.

the sum of each row plus the sum of each column always results in an incorrect calculation, must use Σ for sum3
Adding the sum of the row and the sum of the column will generate an incorrect formula


Steps to Reproduce:
1.get  the sum1 of a row  at d5
2.get the sum2 of a columns at  e5
3.select d5, e5, and f5 at the same time, and then click the sum function Σ in the menu bar. 
we should get =sum(d5:e5), get 18,but f5  automatically generate =sum(e5:e5) , get 13

Actual Results:
but f5  automatically generate =sum(e5:e5) , get 13

Expected Results:
we should get =sum(d5:e5), get 18


Reproducible: Always


User Profile Reset: Yes

Additional Info:
In the past year, I have reproduced this bug in multiple versions of the software and on 6 computers in different office locations. You deleted my last submission record, I ask you to take it seriously this time.
The bug is confirmed to exist, maybe my English level is too poor, so I didn't express it clearly enough.
Comment 1 Yao Fanqing 2025-01-31 06:09:50 UTC
Created attachment 198899 [details]
Adding the sum of the row and the sum of the column will generate an incorrect formula
Comment 2 Cekomote 2025-01-31 10:52:41 UTC
After a lot of tests, I confirm that the Σ button acts inconsistently.

The simplest test I found is :
1. In cell A1, enter 1
2. In cell A2, enter =SUM(A1)
3. Select cell range A1:A2 and use the Σ button to generate a sum formula in A3

Actual result : A3 is =SUM(A2:A2)
Expected result : A3 should be =SUM(A1:A2)

The behavior is the same for all Σ button formulas (Sum, Average, Min, Max, Count, CountA, Product, Stdev, StdevP, Var, VarP).

Full behavior seems to be :
IF the selected range contains a formula in the the Σ button formula list AND if this formula uses
- for formula generation of a column, (a cell OR a cell range of one cell height) of the row above
- for formula generation of a raw, (a cell OR a cell range of one cell width) of the column before
THEN the generated formula has a truncated range.
The range of the generated formula is correct if the other cases.

Exemple if Σ button is used to sum a column
- if A2 is =SUM(A1), A3 will be =SUM(A2:A2) instead of =SUM(A1:A2)
- if A2 is =SUMPRODUCT(A1), A3 will be =SUM(A1:A2)
- if A2 is =SUM(M1:Z1), A3 will be =SUM(A2:A2) instead of =SUM(A1:A2)
- if A2 is =SUM(B2), A3 will be =SUM(A1:A2)

Reproduced in version 24.8.4.2 on MacOS 15.1.1 - There is no Help - About LibreOffice in LibreOffice for MacOS (Apple Silicon).

This seems to be a bug, I change the status to new.
Comment 3 Telesto 2025-01-31 18:19:07 UTC
Also in
Versie: 4.1.0.4 
Build ID: 89ea49ddacd9aa532507cbf852f2bb22b1ace28

and in
LibreOffice 3.3.0 
OOO330m19 (Build:6)
tag libreoffice-3.3.0.4
Comment 4 Telesto 2025-01-31 18:34:38 UTC
@Heiko
Any opinion how this should work. The current case is odd for sure, IMHO. 

1. In cell A1, enter 1
2. In cell A2, enter =SUM(A1)
3. Select cell range A1:A2 and use the Σ button to generate a sum formula. 
Actual result : A3 is =SUM(A2:A2)

However, step 3 doesn't even work for Excel 2003. At least when using FX wizard. It modifies A1

On the other hand: pressing FX in A3 does automatically detected the range A1:A2 by default.

Office 365 (free) does nothing. You always have to define the range
Comment 5 LeroyG 2025-02-02 13:24:14 UTC

*** This bug has been marked as a duplicate of bug 149041 ***
Comment 6 Heiko Tietze 2025-02-03 10:21:15 UTC
A1 = 1, A2 = 2 => Σ returns SUM(A1:B1)
A1 = 1, A2 = SUM(A1) => Σ returns SUM(B1:B1)

A1 = 1, A2 = SQRT(2) => Σ returns SUM(A1:B1)
A1 = 1, A2 = <any range based function>(<any range>) => Σ returns SUM(B1:B1)

Indeed inconsistent. The help says:

Select Function applied with no selected range
LibreOffice automatically suggests a cell range, provided that the spreadsheet contains data. If the cell range already contains a function, you can combine it with the new one to yield the function applied to the range data. If the range contains filters, the Subtotal function is inserted instead of the selected function.
https://help.libreoffice.org/7.3/en-GB/text/scalc/02/06030000.html?DbPAR=CALC

I cannot wrap my mind around "combine it with". Neither Eike's explanation in bug 149041 comment 3. Wonder if this is really a duplicate.
Comment 7 Heiko Tietze 2025-02-03 10:23:26 UTC
Personally, I'd never click on this symbol or any other expecting to extend the selection. The usual behavior is that a function insert the result at the current position overwriting the selection.
Comment 8 Cekomote 2025-02-03 14:18:48 UTC
Created attachment 198942 [details]
Example to show range generation bug

I have read Bug 124643, Bug 144170 and Bug 149041.

There is a bug. I'm sorry for my poor English level so I made the attached sheet.

Let's keep the selection problem when using autosum in Bug 149041. The sheet was made with just one cell selected, the cell in which the autosum generates the formula.

I hope that this will show that bug to everybody.
Comment 9 Cekomote 2025-02-03 14:40:33 UTC
I changed the status and marked it new.

For whose who doubt, open attachment 198942 [details], select cell P11, delete the content and click Σ button to generate a formula. The documentation, even Microsoft's one is poor but I don't think that somebody can say this is an expected feature.