Alternatives to having multiple SUMIF formulas without requiring the user to apply a filter

StackOverflow https://stackoverflow.com/questions/15964313

  •  03-04-2022
  •  | 
  •  

Question

Suppose in your workbook: Sheet1 has a table with 20 columns and approx 1000 rows. Each row belongs to one of 50 categories. The developer cannot make any visible changes to Sheet1.

Sheet2 has a cell where the user can enter an category ID, and is shown the result of a SUMIF on each of Sheet 1's columns.

My understanding is that Excel will iterate through all 1000 columns for each SUMIF, performing the same search 20 times. Is there an alternative to this?

Was it helpful?

Solution

Here's what I've settled on. It definitely would not suit everyones' needs.

Situation:
- I don't want to run SUMIF 20 times on 10000 rows
- I can safely assume there will never be more than 200 rows for each category (ie a group of rows that fulfil my sumif criteria).
- It's also useful for me to have a table with only the rows matching that criteria.

Solution:
I create a table with 200 rows of formulas that will display rows that fit my criteria.

The leftmost column will have row number of the next matching row, or be blank and not search if there are no more.

First line of left column:

IFERROR(MATCH(CategoryID,'DataTable'!B:B,0),"")

Subsequent lines of left column (A2 is the cell above):

IF(A2="","",MATCH(CategoryID,OFFSET('DataTable'!B:B,A2,0,RowsInTable-A2,1),0)+A2))

All cells to the right of this are basic INDEX formulas that use the row number from the leftmost column.

To count the number of found results we use:

=COUNTA(A2:A202)-COUNTBLANK(A2:A202)

We then use the this count and the table to perform nice quick SUMs:

SUM(OFFSET(C:C,0,0,RowCount,1))
Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top