sc/source/ui/StatisticsDialogs/RegressionDialog.cxx |   11 ++++++++---
 1 file changed, 8 insertions(+), 3 deletions(-)

New commits:
commit b129bc808fe846f729f511062e7cbedf24b9047e
Author:     Eike Rathke <er...@redhat.com>
AuthorDate: Fri Nov 26 18:11:31 2021 +0100
Commit:     Caolán McNamara <caol...@redhat.com>
CommitDate: Sat Nov 27 17:28:46 2021 +0100

    Regression Statistics: use cell reference, not fix row to calculate offset
    
    The INDEX() offset was calculated with a fix row number derived
    from the initial output position, like 35-ROW(). That fails if the
    range later is moved or rows inserted/deleted.
    
    Instead, use a cell reference of the cell's current column and
    end row, like ROW($A$34)+1-ROW(). 34+1 to not have things shifted
    if a row is inserted before 35.
    
    Change-Id: I11276c4acb35505576daa1a20ad49a4fcdbaba49
    Reviewed-on: https://gerrit.libreoffice.org/c/core/+/125914
    Reviewed-by: Eike Rathke <er...@redhat.com>
    Tested-by: Jenkins
    (cherry picked from commit 324e5c3942870749fae0e62c1c11a1400b772584)
    Reviewed-on: https://gerrit.libreoffice.org/c/core/+/125898
    Reviewed-by: Caolán McNamara <caol...@redhat.com>

diff --git a/sc/source/ui/StatisticsDialogs/RegressionDialog.cxx 
b/sc/source/ui/StatisticsDialogs/RegressionDialog.cxx
index 5a4002f97d62..153640d75920 100644
--- a/sc/source/ui/StatisticsDialogs/RegressionDialog.cxx
+++ b/sc/source/ui/StatisticsDialogs/RegressionDialog.cxx
@@ -513,7 +513,12 @@ void 
ScRegressionDialog::WriteRegressionEstimatesWithCI(AddressWalkerWriter& rOu
                                                         bool bTakeLogX)
 {
     rOutput.newLine();
-    SCROW nLastRow = rOutput.current(0, 1 + mnNumIndependentVars).Row();
+    ScAddress aEnd( rOutput.current(0, 1 + mnNumIndependentVars));
+    ScRefFlags eAddrFlag = mbUse3DAddresses ? ScRefFlags::ADDR_ABS_3D : 
ScRefFlags::ADDR_ABS;
+    aEnd.IncCol();
+    const OUString aCoeffAddr( aEnd.Format( eAddrFlag, &mDocument, 
mDocument.GetAddressConvention()));
+    aEnd.IncCol();
+    const OUString aStErrAddr( aEnd.Format( eAddrFlag, &mDocument, 
mDocument.GetAddressConvention()));
 
     // Coefficients & Std.Errors ranges (column vectors) in this table (yet to 
populate).
     rTemplate.autoReplaceRange("%COEFFICIENTS_RANGE%",
@@ -553,9 +558,9 @@ void 
ScRegressionDialog::WriteRegressionEstimatesWithCI(AddressWalkerWriter& rOu
         {
             "",
             // This puts the coefficients in the reverse order compared to 
that in LINEST output.
-            "=INDEX(%COEFFICIENTS_REV_RANGE%; 1 ; " + 
OUString::number(nLastRow + 2) + " - ROW())",
+            "=INDEX(%COEFFICIENTS_REV_RANGE%; 1 ; ROW(" + aCoeffAddr + ")+1 - 
ROW())",
             // This puts the standard errors in the reverse order compared to 
that in LINEST output.
-            "=INDEX(%SERRORSX_REV_RANGE%; 1 ; " + OUString::number(nLastRow + 
2) + " - ROW())",
+            "=INDEX(%SERRORSX_REV_RANGE%; 1 ; ROW(" + aStErrAddr + ")+1 - 
ROW())",
             // t-Statistic
             "=%COEFFICIENTS_RANGE% / %SERRORSX_RANGE%",
             // p-Value

Reply via email to