Tuesday, October 9, 2012

A Single Arrayformula to Sum a Filter of All Rows


Question:

This is a link to a simplified version of the spreadsheet I'm trying to build.  

Following is the screenshot of the sheet "Data": 



Following is the screenshot of the sheet "Summary":



On the Summary sheet, I have filter formulas in columns B and C to sum the quantities from the Data sheet that meet two criteria.

The real spreadsheet is more complicated, and I would like to reduce the number of formulas to speed it up and make it more efficient.  Can I replace the filter formulas with one arrayformula per column (or is there a better option)?


Solution:

Keep the first two rows of sheet "Summary" same as it is and put the following formula in the cell A3 of the sheet "Summary":

=ArrayFormula(QUERY(IF({1,0,0};'Data'!B2:B;IF({0,1,0};if(year('Data'!A2:A)=B2;if(month('Data'!A2:A)=B1;ROUND('Data'!H2:H;1);"");"");IF({0,0,1};if(year('Data'!A2:A)=C2;if(month('Data'!A2:A)=C1;ROUND('Data'!H2:H;1);"");""))));"select Col1, sum(Col2), sum(Col3) where Col1 <> '' group by Col1 order by Col1 label sum(Col2) '',sum(Col3) '' ";0))


I hope the above solution will help you, and if you need more help then please do comment below on this blog itself, I will try to help you out.

I also take up private or confidential projects:

If this blog post was helpful to you, and if you think you want to help me too and make my this blog survive then please donate here: http://igoogledrive.blogspot.com/2012/09/donate.html 

Thanks,
Kishan,

No comments:

Post a Comment