+ Reply to Thread
Results 1 to 18 of 18

Sum values based on multiple criteria (comma delimited) in a single cell

  1. #1
    Registered User
    Join Date
    03-01-2010
    Location
    Atlanta, GA
    MS-Off Ver
    Excel 2007
    Posts
    8

    Smile Sum values based on multiple criteria (comma delimited) in a single cell

    Hello all...

    I'm trying to find out if there is a function that will allow me to sum the values for a designated set of critieria that may have one or more values in a cell.

    Attached is a spreadsheet that contains two worksheets, [data] and [target].

    The [data] tab contains the data set to be used with two columns, (code) and (balance).

    The [target] tab contains the results of my "query" with three columns, (code set), (month), and (value).

    In the [target] tab, the (code set) column contains the criteria I want to "filter" the data set by. sometimes there will only be one criteria identified. But other times, there may be two or more criteria identified and separated by commas.

    In the [target] tab, the (value) column and first two rows, I've used the SUMIF function where if the "one" identified criteria is found it will total the sum.

    However, for the last row, how do I get the SUMIF function to recognize that there are multiple criteria values that need to be found then summed?

    Any guidance would be greatly appreciated.

    ML
    Attached Files Attached Files
    Last edited by leem888; 03-03-2010 at 10:52 AM. Reason: Solved

  2. #2
    Forum Expert NBVC's Avatar
    Join Date
    12-06-2006
    Location
    Mississauga, CANADA
    MS-Off Ver
    2003:2010
    Posts
    34,898

    Re: Sum values based on multiple criteria (comma delimited) in a single cell

    In C2:

    =SUMPRODUCT(--ISNUMBER(SEARCH(data!$A$2:$A$20,A2)),data!$B$2:$B$20)

    copied down.
    Where there is a will there are many ways.

    If you are happy with the results, please add to the contributor's reputation by clicking the reputation icon (star icon) below left corner

    Please also mark the thread as Solved once it is solved. Check the FAQ's to see how.

  3. #3
    Registered User
    Join Date
    03-01-2010
    Location
    Atlanta, GA
    MS-Off Ver
    Excel 2007
    Posts
    8

    Re: Sum values based on multiple criteria (comma delimited) in a single cell

    Thank you. Works perfectly!!!

  4. #4
    Registered User
    Join Date
    03-01-2010
    Location
    Atlanta, GA
    MS-Off Ver
    Excel 2007
    Posts
    8

    Re: Sum values based on multiple criteria (comma delimited) in a single cell

    spoke a little too soon. I found a slight issue. In the attached in the [target] tab, rows 6, 7, and 8, you will see that row 6 and row 8 are correct. However, row 7 seems to be adding up the values for Z4 and Z47 even with the criteria only set for Z47.

    Is the search function somehow substring-ing the criteria within the search?

    Can your solution be extended somehow to account for codes that may be similar like the example given?
    Attached Files Attached Files

  5. #5
    Forum Expert NBVC's Avatar
    Join Date
    12-06-2006
    Location
    Mississauga, CANADA
    MS-Off Ver
    2003:2010
    Posts
    34,898

    Re: Sum values based on multiple criteria (comma delimited) in a single cell

    Okay, use:

    =SUMPRODUCT(--ISNUMBER(SEARCH(data!$A$2:$A$20&" ",SUBSTITUTE(A2,","," ")&" ")),data!$B$2:$B$20)

  6. #6
    Registered User
    Join Date
    03-01-2010
    Location
    Atlanta, GA
    MS-Off Ver
    Excel 2007
    Posts
    8

    Re: Sum values based on multiple criteria (comma delimited) in a single cell

    Thanks again. That function worked perfectly...

    Last question. I've attached the sample spreadsheet and I have added a column to both tabs accounting for a department.

    can the function be extented to account for a second criteria?

    For example, in the [target] tab, rows 3, 4, and 5, I have listed what should be the expected value in column F.

    For row 3, if nothing is there, it will grab all the values.
    For row 4, only values for dep1
    For row 5, only values for dep2

    Again, thank you for your guidance...
    Attached Files Attached Files

  7. #7
    Forum Expert NBVC's Avatar
    Join Date
    12-06-2006
    Location
    Mississauga, CANADA
    MS-Off Ver
    2003:2010
    Posts
    34,898

    Re: Sum values based on multiple criteria (comma delimited) in a single cell

    It is possible, yes, but first why would there not be results for rows 2, 6, 7, 8?

  8. #8
    Registered User
    Join Date
    03-01-2010
    Location
    Atlanta, GA
    MS-Off Ver
    Excel 2007
    Posts
    8

    Re: Sum values based on multiple criteria (comma delimited) in a single cell

    oh, there would be, I was just isolating the example. those rows would be "blank" for the (dept) column and show the value for all occurrences of the code set.

  9. #9
    Forum Expert NBVC's Avatar
    Join Date
    12-06-2006
    Location
    Mississauga, CANADA
    MS-Off Ver
    2003:2010
    Posts
    34,898

    Re: Sum values based on multiple criteria (comma delimited) in a single cell

    Then:

    Please Login or Register  to view this content.
    or shorter, but requires confirmation with CTRL+SHIFT+ENTER not just ENTER...

    Please Login or Register  to view this content.
    Last edited by NBVC; 03-02-2010 at 02:23 PM.

  10. #10
    Registered User
    Join Date
    03-01-2010
    Location
    Atlanta, GA
    MS-Off Ver
    Excel 2007
    Posts
    8

    Re: Sum values based on multiple criteria (comma delimited) in a single cell

    ok, that worked as intended.

    However, while trying to mimic the sample against the real data set (over 25k records), My returned, summed values are all wrong. I'm assuming it has something to do with the either the number of rows or perhaps the number of columns ( A thru K).

    I tried to limit the columns, but no success.

    Then create a pivot, but I cannot seem to make the dept column exists as a true column. I can only make it a row header or column header.

    Any thoughts or suggestions?

  11. #11
    Forum Expert NBVC's Avatar
    Join Date
    12-06-2006
    Location
    Mississauga, CANADA
    MS-Off Ver
    2003:2010
    Posts
    34,898

    Re: Sum values based on multiple criteria (comma delimited) in a single cell

    Post a more realistic workbook sample....

  12. #12
    Registered User
    Join Date
    03-01-2010
    Location
    Atlanta, GA
    MS-Off Ver
    Excel 2007
    Posts
    8

    Re: Sum values based on multiple criteria (comma delimited) in a single cell

    i've attached a more realistic sample set. unfortunately, I had to save it as a .xlsx format. I hope you have excel 2007.
    Attached Files Attached Files

  13. #13
    Forum Expert NBVC's Avatar
    Join Date
    12-06-2006
    Location
    Mississauga, CANADA
    MS-Off Ver
    2003:2010
    Posts
    34,898

    Re: Sum values based on multiple criteria (comma delimited) in a single cell

    Did you know you have a bunch of blank rows after 16410 and then you have more data... is that supposed to be there?

    That is why the formula doesn't work... it sees the blanks as part of the count....

    To avoid the blank in the REJ1 column, then try:

    Please Login or Register  to view this content.
    but I don't get 80271 in D2.. I get 105760 (there are other departments in the mix... your pivot table shows only 3 and sums only those 3)

    I assume the original comma delimitations still apply.. that is why you are not using Pivot Table to do this all?
    Last edited by NBVC; 03-02-2010 at 05:41 PM.

  14. #14
    Registered User
    Join Date
    03-01-2010
    Location
    Atlanta, GA
    MS-Off Ver
    Excel 2007
    Posts
    8

    Re: Sum values based on multiple criteria (comma delimited) in a single cell

    Thanks for catching the data issue. I didn't know there were blanks and must have copied the data set twice.

    Nevertheless, the last code example you provided worked perfectly. Thanks again for all the help.

  15. #15
    Forum Expert NBVC's Avatar
    Join Date
    12-06-2006
    Location
    Mississauga, CANADA
    MS-Off Ver
    2003:2010
    Posts
    34,898

    Re: Sum values based on multiple criteria (comma delimited) in a single cell

    If you now that column B won't contain blanks, then you can remove this part:

    --(data!$B$2:$B$25000<>"") in both occurances within the formula... 1 less thing to check and therefore that much more efficient and quicker...

  16. #16
    Registered User
    Join Date
    01-07-2011
    Location
    Reno, Nv
    MS-Off Ver
    Excel 2003
    Posts
    2

    Re: Sum values based on multiple criteria (comma delimited) in a single cell

    See next post. Sorry, I don't see a delete post....
    Last edited by James W; 01-07-2011 at 02:50 PM.

  17. #17
    Registered User
    Join Date
    01-07-2011
    Location
    Reno, Nv
    MS-Off Ver
    Excel 2003
    Posts
    2

    Re: Sum values based on multiple criteria (comma delimited) in a single cell

    This user defined function I wrote will handle this issue:

    Please Login or Register  to view this content.
    Then put this in the cell you want to see the total: '= AddCommaString (a1)' .

    This example will add up cell a1.
    Last edited by James W; 01-07-2011 at 03:00 PM.

  18. #18
    Forum Expert NBVC's Avatar
    Join Date
    12-06-2006
    Location
    Mississauga, CANADA
    MS-Off Ver
    2003:2010
    Posts
    34,898

    Re: Sum values based on multiple criteria (comma delimited) in a single cell

    Welcome to the forum,

    The thread is a bit old now.... but that's okay if you are offering a solution...

    although, you need to wrap all code in code tags per forum rules.

+ Reply to Thread

Thread Information

Users Browsing this Thread

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

Tags for this Thread

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