<html>
    <head>
      <base href="https://bugs.documentfoundation.org/">
    </head>
    <body><table border="1" cellspacing="0" cellpadding="8">
        <tr>
          <th>Bug ID</th>
          <td><a class="bz_bug_link 
          bz_status_UNCONFIRMED "
   title="UNCONFIRMED - Sorting breaks rows data alignement when functions include columns with no data"
   href="https://bugs.documentfoundation.org/show_bug.cgi?id=107779">107779</a>
          </td>
        </tr>

        <tr>
          <th>Summary</th>
          <td>Sorting breaks rows data alignement when functions include columns with no data
          </td>
        </tr>

        <tr>
          <th>Product</th>
          <td>LibreOffice
          </td>
        </tr>

        <tr>
          <th>Version</th>
          <td>5.3.3.2 release
          </td>
        </tr>

        <tr>
          <th>Hardware</th>
          <td>All
          </td>
        </tr>

        <tr>
          <th>OS</th>
          <td>All
          </td>
        </tr>

        <tr>
          <th>Status</th>
          <td>UNCONFIRMED
          </td>
        </tr>

        <tr>
          <th>Severity</th>
          <td>normal
          </td>
        </tr>

        <tr>
          <th>Priority</th>
          <td>medium
          </td>
        </tr>

        <tr>
          <th>Component</th>
          <td>Calc
          </td>
        </tr>

        <tr>
          <th>Assignee</th>
          <td>libreoffice-bugs@lists.freedesktop.org
          </td>
        </tr>

        <tr>
          <th>Reporter</th>
          <td>pp.luca@tiscali.it
          </td>
        </tr></table>
      <p>
        <div>
        <pre>In Tools / Options / LibreOffice Calc / General
select:

[X] Update references when sorting range of cells.


1) Setup a Calc spreadsheet this way:

      A             B          C        D

1     a       =sum(C1:D1)      1        1
2     b       =sum(C2:D2)      2        2
3     c       =sum(C3:D3)      3        3


This way a is worth 2, b is worth 4, c is worth 6, you see:

      A             B            C        D

1     a             2            1        1
2     b             4            2        2
3     c             6            3        3

2) Now select all then sort by column A descending using Data / Sort. You see,
as expected:

      A             B            C        D

1     c             6            3        3
2     b             4            2        2
3     a             2            1        1


3) Now revert to original sorting (ctrl+z), then modify function in B, as to
include column E - which doesn't contain data - in the sum:

      A             B            C        D

1     a       =sum(C1:E1)      1        1
2     b       =sum(C2:E2)      2        2
3     c       =sum(C3:E3)      3        3

The result is the same as in 1, as expected.

4) Now repeat 2): select all then sort by column A descending using Data /
Sort. You get the wrong result in column B:

      A             B            C        D

1     c             2            3        3
2     b             4            2        2
3     a             6            1        1

That's because the references in column B have been wrongfully reordered,
following column A but ignoring C and  D:

      A             B            C        D

1     c       =somma(C3:E3)      3        3
2     b       =somma(C2:E2)      2        2
3     a       =somma(C1:E1)      1        1


5) If (step 3) you add any value in column D, then repeat step 2), sorting
order is correct. That's to say, starting from:

      A             B            C        D       E

1     a       =somma(C1:E1)      1        1
2     b       =somma(C2:E2)      2        2
3     c       =somma(C3:E3)      3        3       3

The descending order on column A produces, as expected:

      A             B            C        D       E

1     c             9            3        3       3
2     b             4            2        2
3     a             2            1        1

=================================================================

This is bad. And it's not the only case when Calc breaks the raws integrity
without any warning. Also see <a class="bz_bug_link 
          bz_status_UNCONFIRMED "
   title="UNCONFIRMED - Autofilter sorting breaks rows data alignment without warning"
   href="show_bug.cgi?id=107385">bug # 107385</a>:
<a class="bz_bug_link 
          bz_status_UNCONFIRMED "
   title="UNCONFIRMED - Autofilter sorting breaks rows data alignment without warning"
   href="show_bug.cgi?id=107385">https://bugs.documentfoundation.org/show_bug.cgi?id=107385</a>

--</pre>
        </div>
      </p>


      <hr>
      <span>You are receiving this mail because:</span>

      <ul>
          <li>You are the assignee for the bug.</li>
      </ul>
    </body>
</html>