How to prevent displaying the total sum of A + B if columns A + B are empty
You can extend the formula to check whether the value in the column to the left is empty or not:

=if(j3&gt;0;sum(h$2:h3);"")