I need to sum the values in a column based on the values in a different column. In the attachment I am trying to return a value in column F based on occurrences of "0" in column D. If the value in column D = 0, then I need to find the next NON 0 value in column D and sum all corresponding cells in column E. If the value in column D is not 0, then return the value in column E. Essentially, the results of the formula, in cell F6 for example, should give the sum of 'E6:E10', with E10 being the variable cell. I have tried the following formula, but it is not working for me:

=IF(D6=0,SUM(E6:ADDRESS(MATCH(NOT(0),D6:E13),2)),E6)

Example 1.xlsx

Please let me know if any more detail is needed.