Put your sum in cell A5 with =SUM(A1:A4) , leaving row 4 blank.
Now you can add a row (select row 4 and Insert Row), and the formula will
adjust with the inserted rows. This is because when you insert a row in
Excel, it inserts the row above the current row. Since the 'current row' in
your example was the sum row, it did not include that row in the formula, and
the formula was not updated. In the method above, the current row (row 4)
would be in the formula in cell A5, and it will be adjusted when you insert
the new row.