+ Reply to Thread
Results 1 to 18 of 18

Sum column based on multiple criteria in another column

  1. #1
    Registered User
    Join Date
    05-05-2010
    Location
    Leeds, England
    MS-Off Ver
    Excel 2007
    Posts
    31

    Sum column based on multiple criteria in another column

    Hello,

    I typed the formula below in one of my excel worksheets and it worked great. I dragged it across, no problem. But when I try to copy it to another cell, I get an error. If I insert a new row below the row where I typed the formula all the cells above change into the #VALUE error. Please help.

    =SUM(SUMIFS('File PathSummary'!D:D,'File PathSummary'!$C:$C,{131,132,133,138}))

    Apparently this is common when using SUMIFS in excel 97-2003 worksheets.

    So I tried

    = SUM(IF('File PathSummary'!$C:$C={131,132,133,138}, 'File PathSummary'!D:D,0))

    But it is an array function and I want to avoid that.

    Is there any other thing I can do?

    Thanks in advance.

  2. #2
    Forum Guru AlKey's Avatar
    Join Date
    07-20-2009
    Location
    Lakeland, FL USA
    MS-Off Ver
    Microsoft Office 2010/ Office 365
    Posts
    8,903

    Re: Sum column based on multiple criteria in another column

    Try it like this
    Formula: copy to clipboard
    Please Login or Register  to view this content.


    You may want to upload an excel file to speed up the process
    Last edited by AlKey; 05-12-2016 at 11:55 AM.
    If you like my answer please click on * Add Reputation
    Don't forget to mark threads as "Solved" if your problem has been resolved

    "Nothing is so firmly believed as what we least know."
    --Michel de Montaigne

  3. #3
    Forum Expert Tony Valko's Avatar
    Join Date
    12-31-2011
    Location
    Pittsburgh
    MS-Off Ver
    2002, 2007:2013
    Posts
    18,890

    Re: Sum column based on multiple criteria in another column

    Quote Originally Posted by CNN View Post
    I dragged it across, no problem. But when I try to copy it to another cell, I get an error.
    Dragging it across IS copying it to another cell.

    Don't know why you'd get an error.

    Apparently this is common when using SUMIFS in excel 97-2003 worksheets.
    SUMIFS is not available in Excel versions 97-2003. It was introduced in Excel 2007.
    Biff
    Microsoft MVP Excel
    Keep It Simple Stupid

    Let's Go Pens. We Want The Cup.

  4. #4
    Registered User
    Join Date
    05-05-2010
    Location
    Leeds, England
    MS-Off Ver
    Excel 2007
    Posts
    31

    Re: Sum column based on multiple criteria in another column

    Quote Originally Posted by AlKey View Post
    Try it like this
    Formula: copy to clipboard
    Please Login or Register  to view this content.


    You may want to upload an excel file to speed up the process
    Sorry about that. The file contains some confidential info.

    And SUMIF has that same problem with SUMIFS. If the source file is not open, I get the #VALUE error when writing the formula.

  5. #5
    Forum Expert Tony Valko's Avatar
    Join Date
    12-31-2011
    Location
    Pittsburgh
    MS-Off Ver
    2002, 2007:2013
    Posts
    18,890

    Re: Sum column based on multiple criteria in another column

    Use SUMPRODUCT...

    =SUMPRDOUCT(--ISNUMBER(MATCH('File PathSummary'!$C1:$C100,{131,132,133,138},0)),'File PathSummary'!D1:D100)

    You should avoid using entire columns as range references in the SUMPRODUCT function. Use smaller specific ranges.
    Last edited by Tony Valko; 05-16-2016 at 09:35 AM.

  6. #6
    Registered User
    Join Date
    05-05-2010
    Location
    Leeds, England
    MS-Off Ver
    Excel 2007
    Posts
    31

    Re: Sum column based on multiple criteria in another column

    Quote Originally Posted by Tony Valko View Post
    Use SUMPRODUCT...

    =SUMPROUCT(--ISNUMBER(MATCH('File PathSummary'!$C1:$C100,{131,132,133,138},0)),'File PathSummary'!D1:D100)

    You should avoid using entire columns as range references in the SUMPRODUCT function. Use smaller specific ranges.
    Thank you so much. This worked out perfectly.

    I'm still new to Excel on this level. Could you please explain what the formula does?

  7. #7
    Registered User
    Join Date
    05-05-2010
    Location
    Leeds, England
    MS-Off Ver
    Excel 2007
    Posts
    31

    Re: Sum column based on multiple criteria in another column

    Quote Originally Posted by Tony Valko View Post
    Use SUMPRODUCT...

    =SUMPROUCT(--ISNUMBER(MATCH('File PathSummary'!$C1:$C100,{131,132,133,138},0)),'File PathSummary'!D1:D100)

    You should avoid using entire columns as range references in the SUMPRODUCT function. Use smaller specific ranges.

    Thank you so much. This worked out perfectly.

    I'm still new to Excel on this level. Could you please explain what the formula does?

  8. #8
    Forum Expert Tony Valko's Avatar
    Join Date
    12-31-2011
    Location
    Pittsburgh
    MS-Off Ver
    2002, 2007:2013
    Posts
    18,890

    Re: Sum column based on multiple criteria in another column


  9. #9
    Registered User
    Join Date
    05-05-2010
    Location
    Leeds, England
    MS-Off Ver
    Excel 2007
    Posts
    31

    Re: Sum column based on multiple criteria in another column

    I'm still going through the page you sent me. It's very interesting. I was reading and practising the MATCH function and I noticed that the syntax is MATCH(lookup_value, lookup_array, [match_type]). I was wondering why your formula worked.

  10. #10
    Forum Expert Tony Valko's Avatar
    Join Date
    12-31-2011
    Location
    Pittsburgh
    MS-Off Ver
    2002, 2007:2013
    Posts
    18,890

    Re: Sum column based on multiple criteria in another column

    Let's see how this works using a small sample...

    Data Range
    A
    B
    C
    D
    1
    X
    30
    118
    2
    Y
    41
    3
    Z
    71
    4
    Z
    17
    5
    Y
    73
    6
    ------
    ------
    ------
    ------


    This formula entered in D1:

    =SUMPRODUCT(--ISNUMBER(MATCH(A1:A5,{"X","Z"},0)),B1:B5)

    MATCH returns the position number of the lookup value RELATIVE to the lookup array if the lookup value is found. If the lookup value is not found then MATCH returns the #N/A error value.

    This is how that would look:

    A1: MATCH("X",{"X","Z"},0) = 1
    A2: MATCH("Y",{"X","Z"},0) = #N/A
    A3: MATCH("Z",{"X","Z"},0) = 2
    A4: MATCH("Z",{"X","Z"},0) = 2
    A5: MATCH("Y",{"X","Z"},0) = #N/A

    We then test to see if MATCH found the lookup value by testing the result as being a number and not the #N/A error:

    A1: ISNUMBER(1) = TRUE
    A2: ISNUMBER(#N/A) = FALSE
    A3: ISNUMBER(2) = TRUE
    A4: ISNUMBER(2) = TRUE
    A5: ISNUMBER(#N/A) = FALSE

    SUMPRODUCT works with numbers so we have to convert those TRUE and FALSE to numbers. One way to do that is using the double unary minus --.

    --TRUE = 1
    --FALSE = 0

    A1: --TRUE = 1
    A2: --FALSE = 0
    A3: --TRUE = 1
    A4: --TRUE = 1
    A5: --FALSE = 0

    This array of 1s and 0s is then multiplied with the values in B1:B5...

    1 * 30 = 30
    0 * 41 = 0
    1 * 71 = 71
    1 * 17 = 17
    0 * 73 = 0

    These results are then summed for the final result of the formula:

    SUMPRODUCT({30;0;71;17;0}) = 118

    So:

    =SUMPRODUCT(--ISNUMBER(MATCH(A1:A5,{"X","Z"},0)),B1:B5) = 118

  11. #11
    Registered User
    Join Date
    05-05-2010
    Location
    Leeds, England
    MS-Off Ver
    Excel 2007
    Posts
    31

    Re: Sum column based on multiple criteria in another column

    Thanks. When I read the article you sent to me, I understood your calculation. The only part that stumped me was the fact the the syntax for the MATCH function seems to be switched.
    The syntax is MATCH(lookup_value, lookup_array, [match_type])
    Yours appears to be MATCH(lookup_array, lookup_value, [match_type]).

    I might be mistaken but I though the lookup_ array was supposed to be the column we were searching and the look_up values were the ones I specified in the brackets.

  12. #12
    Forum Expert Tony Valko's Avatar
    Join Date
    12-31-2011
    Location
    Pittsburgh
    MS-Off Ver
    2002, 2007:2013
    Posts
    18,890

    Re: Sum column based on multiple criteria in another column

    Quote Originally Posted by CNN View Post
    I might be mistaken but I though the lookup_ array was supposed to be the column we were searching and the look_up values were the ones I specified in the brackets.
    No, it's the other way around.

    The lookup values are the range values A1:A5.

    The lookup array are the values in the brackets {"X","Z"}.

  13. #13
    Registered User
    Join Date
    05-05-2010
    Location
    Leeds, England
    MS-Off Ver
    Excel 2007
    Posts
    31

    Re: Sum column based on multiple criteria in another column

    OK but if was search for just Y in column A, will the function remain as written or will it now be

    MATCH("Y", A1:A5,0)

  14. #14
    Forum Expert Tony Valko's Avatar
    Join Date
    12-31-2011
    Location
    Pittsburgh
    MS-Off Ver
    2002, 2007:2013
    Posts
    18,890

    Re: Sum column based on multiple criteria in another column

    It would still be:

    MATCH(A1:A5,{"Y"},0)

    However, if there is just a single criteria to match then we would do it like this:

    =SUMPRODUCT(--(A1:A5="Y"),B1:B5)

  15. #15
    Registered User
    Join Date
    05-05-2010
    Location
    Leeds, England
    MS-Off Ver
    Excel 2007
    Posts
    31

    Re: Sum column based on multiple criteria in another column

    Hmm. I tried using MATCH(A1:A5,{"Y"},0) but it didn't work. But MATCH("Y", A1:A5,0) worked.

    Oh well, I'll go back and study some more. Thanks for all your help.

  16. #16
    Forum Expert Tony Valko's Avatar
    Join Date
    12-31-2011
    Location
    Pittsburgh
    MS-Off Ver
    2002, 2007:2013
    Posts
    18,890

    Re: Sum column based on multiple criteria in another column

    MATCH("Y", A1:A5,0)

    Will return the position number of the lookup value "Y" within the range A1:A5.

    Based on the table below that result would be 2.

    Data Range
    A
    B
    C
    1
    X
    30
    114
    2
    Y
    41
    3
    Z
    71
    4
    Z
    17
    5
    Y
    73
    6
    ------
    ------
    ------


    However, in your application where you want a conditional sum it's the other way around:

    Either one of these formulas entered in C1:

    =SUMPRODUCT(--ISNUMBER(MATCH(A1:A5,{"Y"},0)),B1:B5)

    =SUMPRODUCT(--(A1:A5="Y"),B1:B5)

  17. #17
    Registered User
    Join Date
    05-05-2010
    Location
    Leeds, England
    MS-Off Ver
    Excel 2007
    Posts
    31

    Re: Sum column based on multiple criteria in another column

    Ok so if I am using the MATCH function as a standalone function, I use one syntax but if I am using it to get a conditional sum, I switch the syntax? That's kind of confusing.

  18. #18
    Forum Expert Tony Valko's Avatar
    Join Date
    12-31-2011
    Location
    Pittsburgh
    MS-Off Ver
    2002, 2007:2013
    Posts
    18,890

    Re: Sum column based on multiple criteria in another column

    Yeah, it can be confusing until you get the hang of it.

+ Reply to Thread

Thread Information

Users Browsing this Thread

There are currently 1 users browsing this thread. (0 members and 1 guests)

Similar Threads

  1. [SOLVED] Find unique cells in column -> Sum another column based on multiple criteria
    By mjoc9 in forum Excel Formulas & Functions
    Replies: 7
    Last Post: 08-20-2015, 09:29 AM
  2. [SOLVED] Average one column based on multiple criteria
    By smartbuyer in forum Excel General
    Replies: 7
    Last Post: 03-13-2015, 04:37 AM
  3. [SOLVED] Sum Second Column based on Multiple Criteria from First Column
    By Zimbo in forum Excel Formulas & Functions
    Replies: 2
    Last Post: 03-09-2015, 10:01 AM
  4. Replies: 20
    Last Post: 07-03-2014, 09:00 AM
  5. [SOLVED] Please help : Sum of column based on multiple criteria
    By kamalchandra.15 in forum Excel Formulas & Functions
    Replies: 4
    Last Post: 11-06-2013, 02:22 AM
  6. Replies: 7
    Last Post: 06-25-2013, 07:15 PM
  7. [SOLVED] Calculate SUM based on multiple criteria (row and column)
    By Flyinace2000 in forum Excel Formulas & Functions
    Replies: 8
    Last Post: 11-29-2012, 12:33 PM

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts

Search Engine Friendly URLs by vBSEO 3.6.0 RC 1