+ Reply to Thread
Results 1 to 13 of 13

Sum column and count distinct values in another based on multiple criteria

  1. #1
    Registered User
    Join Date
    03-08-2012
    Location
    London
    MS-Off Ver
    Excel 2010
    Posts
    27

    Sum column and count distinct values in another based on multiple criteria

    Hi All, I need help with problem I've been wrestling with for a couple of week now (and until now have been too proud to ask for help on). I have a table with multiple columns (20 in total). However I would like a someone to help with with a formula that looks at only needs to consider three of them.

    The first two columns are references and the third will contain a negetive number. I would like someone to help me with a formula that does the following
    Criteria 1: Looks at the first column and finds all the references that are exactly the same (ie BATCH/0407), then
    Criteria 2: Looks at the second column that has all references that are the same (for criteria 1) [ie 830 REVISE PATH (WITH CABL]
    Criteria 3: Add together all the the numbers in the third column that match criteria 1 & 2 (ie add -20 to -42)

    Sample data is below (hopefully the columns align). If not I've uploaded sample data in spread sheet named Example data.xlsx

    However, I also would like the results to show the Batch and Type too (as these result will be on another sheet with the workbook and -44 on it's own won't mean much. Using the ones with the green background (for example) the result would be -44. I have also included a table of expected results.

    So I guess the actual result for the example would be │Batch/0621 │ 810 New Path (Cable) │ -44 │and I would like this formula to do this for the whole spreadsheet (which contains several thousand entries)

    I would be grateful for any assistance anyone can offer.


    Batch │ Type │ Ontime / Early
    BATCH/0072 850 REVISE PATH (WITHOUT C -20
    BATCH/0407 830 REVISE PATH (WITH CABL -20
    BATCH/0407 830 REVISE PATH (WITH CABL -42
    BATCH/0439 850 REVISE PATH (WITHOUT C -11
    BATCH/0440 850 REVISE PATH (WITHOUT C -11
    BATCH/0477 850 REVISE PATH (WITHOUT C -20
    BATCH/0619 902 NEW CUSTOMR (NO CABLE) -20
    BATCH/0619 902 NEW CUSTOMR (NO CABLE) -5
    BATCH/0621 810 NEW PATH (CABLE) -20
    BATCH/0621 810 NEW PATH (CABLE) -12
    BATCH/0621 810 NEW PATH (CABLE) -1
    BATCH/0621 810 NEW PATH (CABLE) -8
    BATCH/0621 810 NEW PATH (CABLE) -3

    BATCH/0661 820 NEW PATH (NO CABLE) -20
    BATCH/0661 820 NEW PATH (NO CABLE) -1
    BATCH/0661 820 NEW PATH (NO CABLE) -10

    Thank you in advance for all those who attempt to help.
    Attached Files Attached Files

  2. #2
    Forum Expert Sam Capricci's Avatar
    Join Date
    06-14-2012
    Location
    Palm Harbor, Florida
    MS-Off Ver
    16.84 for Mac MS 365
    Posts
    8,496

    Re: Sum column and count distinct values in another based on multiple criteria

    not completely sure but will this work for you? used a sumifs formula in col J as an example.
    Attached Files Attached Files
    Make contributors happy, click on the "* Add Reputation" as a way to say thank you.
    Sam Capricci

  3. #3
    Forum Expert
    Join Date
    09-11-2014
    Location
    Washington, DC
    MS-Off Ver
    2016
    Posts
    1,907

    Re: Sum column and count distinct values in another based on multiple criteria

    Try this in cell I4 and drag down:

    Please Login or Register  to view this content.
    Sambo kid, note that I also started with SUMIFS but some of the criteria ranges include spaces before text, so SUMIFS won't grab all the correct values.

    Hope this helps!
    Last edited by mcmahobt; 01-12-2015 at 10:48 AM.
    Spread the love, add to the Rep

    "None of us are as smart as all of us."

  4. #4
    Forum Expert Sam Capricci's Avatar
    Join Date
    06-14-2012
    Location
    Palm Harbor, Florida
    MS-Off Ver
    16.84 for Mac MS 365
    Posts
    8,496

    Re: Sum column and count distinct values in another based on multiple criteria

    Mcmahobot, I was having difficulty discerning his needs. I see what you did, nice. gave you a bump for it.

  5. #5
    Registered User
    Join Date
    03-08-2012
    Location
    London
    MS-Off Ver
    Excel 2010
    Posts
    27

    Re: Sum column and count distinct values in another based on multiple criteria

    Hi SK,

    Thank you for your efforts and speedy response. Sadly the results you included in column J do not match those in column I in my expected output example.

  6. #6
    Forum Expert Sam Capricci's Avatar
    Join Date
    06-14-2012
    Location
    Palm Harbor, Florida
    MS-Off Ver
    16.84 for Mac MS 365
    Posts
    8,496

    Re: Sum column and count distinct values in another based on multiple criteria

    Yeah, i noticed that, I believe Mcmahobt's formula looks like it got it for you if I understand what you needed and what he wrote. try his instead.

  7. #7
    Registered User
    Join Date
    03-08-2012
    Location
    London
    MS-Off Ver
    Excel 2010
    Posts
    27

    Re: Sum column and count distinct values in another based on multiple criteria

    Hi Mcmahobt, this is spot on. Thank you.

    One more question, if I may. The important data is in the Type column, so I would always expect to have to specify this in any formula. However, what if the actual Batch isn't? Is there a way of just counting the number of different Batch numbers for each of the Types. Then adding the values together that correspond to values in 'Ontime / Early column'? Hope this makes sense?

    Last edited by mike.greene; 01-12-2015 at 11:12 AM. Reason: Grammatical Error Corrections

  8. #8
    Forum Expert
    Join Date
    09-11-2014
    Location
    Washington, DC
    MS-Off Ver
    2016
    Posts
    1,907

    Re: Sum column and count distinct values in another based on multiple criteria

    Could you try explaining what you mean a little more; perhaps use some examples?

    If what you mean is what if there is only one criteria, either Batch or Type, but not both columns, then yes - you can still use this formula. Just remove the data between the "*" that corresponds to that data range that is removed.
    Last edited by mcmahobt; 01-12-2015 at 11:16 AM.

  9. #9
    Forum Expert
    Join Date
    07-20-2011
    Location
    Mysore, India.
    MS-Off Ver
    Excel 2019
    Posts
    8,583

    Re: Sum column and count distinct values in another based on multiple criteria

    Pl see file, ARRAY formulas are used.(extra spaces are removed)

    ARRAY Formula for 1st and 2nd column
    Please Login or Register  to view this content.
    Formula for 3rd column
    Please Login or Register  to view this content.
    ARRAY formula is used

    To enter ARRAY formula
    Paste the formula
    Press F2
    Press Ctrl+Shift+Enter keys together.
    Attached Files Attached Files

  10. #10
    Registered User
    Join Date
    03-08-2012
    Location
    London
    MS-Off Ver
    Excel 2010
    Posts
    27

    Re: Sum column and count distinct values in another based on multiple criteria

    Hi memahobt,

    I've included the same sample data, but with the results expected in columns F to H

    Thanks
    Attached Files Attached Files

  11. #11
    Forum Expert
    Join Date
    09-11-2014
    Location
    Washington, DC
    MS-Off Ver
    2016
    Posts
    1,907

    Re: Sum column and count distinct values in another based on multiple criteria

    Try this in H5 and drag down:

    Please Login or Register  to view this content.
    Hope this helps!

    EDIT: If you also want the Batch Qty., paste this into F5 and drag down:

    Please Login or Register  to view this content.
    Last edited by mcmahobt; 01-12-2015 at 11:41 AM.

  12. #12
    Registered User
    Join Date
    03-08-2012
    Location
    London
    MS-Off Ver
    Excel 2010
    Posts
    27

    Re: Sum column and count distinct values in another based on multiple criteria

    Hi mcmahobt, that works perfectly for the Ontime / Early column, however, I also need the formula that would give the Batch Qty for the given type (sorry, it's me, I didn't explain it very well).

  13. #13
    Registered User
    Join Date
    03-08-2012
    Location
    London
    MS-Off Ver
    Excel 2010
    Posts
    27

    Re: Sum column and count distinct values in another based on multiple criteria

    Spot on again. You're awsome!!

    You have really helped me. I spent all weekend trying to work these problems out (without success).

    Thank you so much


+ 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. Replies: 7
    Last Post: 01-29-2015, 10:14 AM
  2. Count distinct values that correspond to a criteria
    By Eduard in forum Excel Programming / VBA / Macros
    Replies: 23
    Last Post: 04-22-2013, 01:03 PM
  3. Distinct count based on multiple criteria - am I on the right track?
    By thedunnyman in forum Excel Formulas & Functions
    Replies: 3
    Last Post: 03-26-2012, 07:36 AM
  4. Replies: 5
    Last Post: 03-13-2012, 06:05 AM
  5. Count distinct values with criteria
    By greencardioid in forum Excel Formulas & Functions
    Replies: 6
    Last Post: 07-29-2008, 06:48 PM

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