Multiple criteria sumif array formula with logic

Hi Thinh. I’ve tried to integrate this into my app and all seems to work well apart from one issue:

When manually generating a new row through the ‘add new rows at bottom’ button it works great. The issue is that the data is coming in through a form on a second tab which is pushed through to sheet 1 through an array formula reference.

As a consequence each time a new entry is added to the form tab 500 new rows are generated and the column D formula is not copied down.

I’ve illustrated this problem in the same example document. Here is the link again: https://docs.google.com/spreadsheets/d/1MYDEB8-7F0SUCO6l7OIjYYjrC60DbeNKoOlFdFLmU4k/edit?usp=sharing