Each command problem with row contain if command
It's hard to describe. Please see the template and result for more details.
As you can see, it happened to the first and second row. The last 2 cells of total row is put to the first row and second row has merge cell of the total row which it shouldn't be merged.