
Originally Posted by
dflak
The main reason the SUMPRODUCT formula fails is that all the arrays in the formula have to be the same size. What you need to do is find out where the month is, and define a range that contains the same number of rows as the other criteria in this column. It will probably make more sense with an example:
To find out where Oct occurs, Use =MATCH(C2,Sheet2!1:1,0) - This is Cell F2 in my example and the result is 17. Oct is the 17th column on the spreadsheet.
To define a range of cells, now that we know the column use OFFSET(Sheet2!A:A,0,F2-1) - This is part of the formula in cell G2. It means take the range A:A on sheet2, shift it down 0 rows and move it over F2-1 columns. The reason for the minus 1 is that Match starts counting at 1 but offset starts counting at zero. So go to Column A and go 16 columns over.
For some reason, when I put this in SUMPRODUCT it doesn't work, but SUMIFS does work. So the formula in Cell G2 is =SUMIFS(OFFSET(Sheet2!A:A,0,F2-1),Sheet2!C:C,A2,Sheet2!E:E,B2).
I took the formula in F2 and copied and pasted into this formula to get: =SUMIFS(OFFSET(Sheet2!A:A,0,MATCH(C2,Sheet2!1:1,0)-1),Sheet2!C:C,A2,Sheet2!E:E,B2) - This formula eliminates the helper column.
To John's point. I did another version of the spreadsheet using an Excel Table. Not only is the formula easier to read, but it reduces the amount of work Excel has to do by about a factor of 100,000 in this case.
Bookmarks