Question

I'm trying to return the sum of a range of cells if an associated value is in a range of values used as filtering conditions. For example, using the following data table:

  Keys      Values
   A        500
   B        300
   C        600
   D         20
   A        150
   C        600

and the following list of keys to be summed:

Sum Keys:
   A
   D

I'm looking for a formulaic way to return 500+20+150 = 670.

I know you can use multiple SUMIFs, but the number of keys will change based on what the user wants to filter on, and writing enough SUMIFs to cover the max realistic cases (like 10ish) seems excessive, and I feel like there must be an easier way.

In my head, the formula would look something like this:

=SUMIFS(Values, Keys, OR(Sum Keys), ...(optional other conditions))

I realize that this is an easy VBA problem, but I'm trying to avoid that because the spreadsheet will be audited by people with varying (or no) VBA knowledge. Also, adding an indicator column to the data to show if the key is in the Sum Keys range isn't realistic because there will be multiple tabs summarizing the data, each with their own filters on Key

Any help is appreciated, though I realize this may be impossible without VBA. Please let me know if more information is needed.

Thanks!

EDIT: Thanks barry houdini for the answer! See the comments of his post for the general solution for summing based on multiple ranges of acceptable criteria.

Was it helpful?

Solution

You can use a formula like this

=SUMPRODUCT(SUMIFS(Values,Key,Sum_Keys))

If Sum_Keys has 4 values then the SUMIFS formula returns a 4 value "array" (one for each Key in Sum_Keys) so you then need another function to sum that array. I use SUMPRODUCT because it avoids the need for "array entry".

You can add more conditions in the usual way, e.g.

=SUMPRODUCT(SUMIFS(Values,Key,Sum_Keys,Dates,Specifc_date))

OTHER TIPS

If you want to sum items in accordance to filter conditions, consider using the

=SUBTOTAL()

worksheet function. It is the tool to handle this task.

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top