Google-sheets – SUMPRODUCT inside ARRAYFORMULA in Google Sheets

google sheets

I have a SUMPRODUCT equation that works fine on one row:

=SUMPRODUCT(O4:O10-O3:O9,E2-P4:P10,N(E2>P4:P10))

However, instead of copying it for each E row I want to use ARRAYFORMULA to automatically generate the values using E2:E.

When I try the following:

=ARRAYFORMULA(SUMPRODUCT(O4:O10-O3:O9,E2:E-P4:P10,N(E2:E>P4:P10)))

I get the error Array arguments to MINUS are of different size.

I know there is another question asking something similar, but there is no explanation of the formula in the answer so I cannot apply it to my situation easily.

Best Answer

The error is caused by this part

E2:E-P4:P10

The end part in E2:E is an open reference, meaning that it will be take the last row of the sheet.

One possible solution could be to change E2:E by E2:E8 or something similar in order to make this part of the formula have the same number of rows as P4:P10