+ Reply to Thread
Results 1 to 10 of 10

Counting Unique combinations

  1. #1
    Registered User
    Join Date
    09-29-2007
    Posts
    3

    Counting Unique combinations

    Can someone, anyone please help. I have a spreadsheet that has 2 columns. The first is a vendor code, and the second is a part #. There are many vendors with multiple part #'s per vendor and duplicates. In other words, (for example sake), a vendor has 20 part numbers associated with a particular vendor #,and there are many duplicates within the list.

    I am trying to do a vlookup and count how many items are associated with the vendor. But I have to exclude duplicates and only count the part once? This is very frustrating. Is this even possible? ANY help would be appreciated. Below is an example.....

    SHEET 1
    Column A (supplier)......................Column B (part#)
    xyz corp.......................................12345
    xyz corp........................................78910
    xyz corp.......................................12345
    ABC Corp......................................99999
    ABC Corp......................................55555
    ABC Corp......................................99999

    SHEET 2
    Column A (supplier)................Column B(# of parts)
    xyz corp.....................................2
    ABC Corp...................................2


    So based on this, I want to COUNT how many times the part # shows up for xyz, and ABC and then I need it input into another sheet. So the logic verbally would be......lookup xzy in the first sheet, count how many exclusive times the part # shows up for that supplier, and return that count in the new sheet.

    I hope that make sense.
    Last edited by t8jones; 05-27-2010 at 09:25 PM.

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

    Re: Most frustrating vlookup, if, count formula

    Can be done easily in a few steps, without complex formulas...

    You can use Advanced Filter in Data menu, to get a unique list of vendors and parts..

    Select columns A and B and go to Data|Filter|Advanced Filter.

    check Unique Parts Only and select where you want result to go.

    Click ok, you should have unique part ids and corresponding vendors.

    You can create another unique list based only on the Vendor Column to get a unique list of Vendors.

    Then you can use Countif to count how many times the unique vendor appears in the first list you created of unique vendor/parts.


    =Countif(X:X,Z1) where Z1 contains the Vendor in the unique list of vendors and X:X is the list of vendors in the unique vendor/part list.
    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
    09-29-2007
    Posts
    3

    Re: Counting Unique combinations

    Thanks, but I actually need a complex formula. ahaha. The reason is because what I am doing is running a large report from our system that has about 20 columns, and then I want to paste that report into a worksheet, and then let the vlookup do its work to pull the data. I have to do this report every month, and counting this one parameter is just one of the functions that I am doing a vlookup on. So I want to paste the raw data in and not have to filter etc. I hope that makes sense.

  4. #4
    Forum Expert
    Join Date
    12-03-2009
    Location
    Florence, Italy
    MS-Off Ver
    Excel 2019
    Posts
    1,796

    Re: Counting Unique combinations

    Hi,
    to obtain a list of the SUPPLIER of column A in Sheet1, you could try this array formula in cell B2 of sheet2Array formula has to be confirmed with control+shift+enter.
    You must drag down the formula until "error" pops up.

    =INDEX(Sheet1!$A$2:$A$3000,SMALL(IF(ISNUMBER(MATCH(ROW(Sheet1!$A$2:$A$3000)-1,MATCH(Sheet1!$A$2:$A$3000,Sheet1!$A$2:$A$3000,0),0)),MATCH(Sheet1!$A$2:$A$3000,Sheet1!$A$2:$A$3000,0),""),ROW(Sheet1!A1)))

    You can also nest the formula inside a IF formula, to avoid errors

    =IF(ISERROR(formula);"";formula)

    Using condional formatting to blank errors is another solution.
    --------------------------------------------

    To obtain the unique number of the PART (column B sheet1) per SUPPLIER (column A sheet1) you could try another array formula (thanks to Mike Gel Girvin)

    =SUM(IF(FREQUENCY(IF(Sheet1!A2:A3000=A2,IF(Sheet1!A2:A3000<>"",MATCH("~"&Sheet1!B2:B3000,Sheet1!B2:B3000&"",0))),ROW(Sheet1!B2:B3000)-ROW(Sheet1!B2)+1),1,0))

    Both the formula are very challenging for processor.
    Hoping did not make any mistake in translation from Excel.
    Last edited by canapone; 05-28-2010 at 08:12 AM.

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

    Re: Counting Unique combinations

    As CANAPONE states, the array formulas can be a bit taxing on the processor.

    Maybe with the help of a helper column, you can use a pivot table...

    Say your data is in column A:B, then in C1 enter a title, like CountParts and in C2 enter formula like:

    =IF(SUMPRODUCT(($A$2:$A2=A2)*($B$2:$B2=B2))>1,0,1)

    and copy down.

    This formula too can be limiting if you drag down to far.. so try to limit.

    NOTE: If part numbers are unique to the suppliers (i.e. Part numbers are not shared, then use this less taxing formula: =IF(COUNTIF($B$2:$B2,B2)>1,0,1) instead of the Sumproduct() formula.

    Then use a Pivot table to summarize that column

    Go to Data|Pivot Table, clikc Next.

    Ensure you have correct range, click Next

    Click Layout and drag the Supplier button to the Row Area, drag the CountParts button to the Data Area... It should say Sum of CountParts ... if not double-click that button in the Data Area and choose sum.

    Then determine where you want Pivot table to go,

    Click Finish.
    Attached Files Attached Files

  6. #6
    Registered User
    Join Date
    09-29-2007
    Posts
    3

    Re: Counting Unique combinations

    Thanks everyone for the info, but I still cant get it. I definately can not use a pivot table.

    I attached a sheet as an example. So what I want to do is simply put a vlookup formula in sheet 1 (cell A2-A75) that will look up all the values in sheet 2 and count how many EXCLUSIVE "part #'s" come up for each spcific vendor.

    For example - supplier C508 has 168 parts in total but many are the same. So there are actually only 122 (I think) after getting rid of all the duplicates. So I want cell A2 on sheet 1to have a formula that will pull 122 into the cell?

    I hope that makes sense. Any help appreciated because this is driving me nuts!!!
    Attached Files Attached Files

  7. #7
    Forum Expert
    Join Date
    12-03-2009
    Location
    Florence, Italy
    MS-Off Ver
    Excel 2019
    Posts
    1,796

    Re: Counting Unique combinations

    Hi, (I'm working on your file),
    you could copy in c2 of sheet2 the NBVC's suggested formula

    =IF(SUMPRODUCT(($A$2:$A2=A2)*($B$2:$B2=B2))>1,0,1)

    and you drag the formula till row 3158

    In sheet1 you could use in B2 a SUMIF
    =SUMIF(Sheet2!$A$2:$C$3158,A2,Sheet2!$C$2:$C$3158)

    In the file you could also see and test as the Array formula (highlighted in yellow: sheet1) do their job correctly, but not smoothly.


    http://myfreefilehosting.com/f/05b92da21a_0.12MB


    Hope it's a step forward
    Last edited by canapone; 06-01-2010 at 12:41 AM.

  8. #8
    Valued Forum Contributor Miraun's Avatar
    Join Date
    04-03-2009
    Location
    New England
    MS-Off Ver
    2003, 2007, 2010, 2013
    Posts
    554

    Re: Counting Unique combinations

    VLookup is used for looking up other columns of information with the same designation, it cannot be used for this fashion. You're looking for a complex count statement that will be invoking array formulas. If your spreadsheet is too large to be running a pivot table, then setting up array formulas is going to be more of a strain on your computer.

    NBCV's first reply is likely the easiest and fastest way to get at the results you want... there are a couple additional steps that you can do in order to make it the most hands off that you're looking for.

    Since you're using a new version of excel (by your xmlx extension), you're able to use the advanced filter to copy the results to another worksheet. Since you supplied an example with all unique vendor codes, I assume that the vendors are consistent.

    You do not need to copy all of the information to another sheet, only the two relevant columns, otherwise it will not properly filter. If you always replace the information in this additional sheet with the distinct values from this filter, then you won't need to replace the countif statements.
    Attached Files Attached Files

  9. #9
    Registered User
    Join Date
    08-11-2010
    Location
    Paris, France
    MS-Off Ver
    Excel 2003
    Posts
    2

    Integrate CountDiff function into VBA formula

    Hello,

    I have the following

    A B C D
    Functional Area Evolution Request Reference required man days required cost

    Collateral ref001 10 100 $
    Collateral ref001 5 50 $
    Payment Incident ref002 15 80$


    For each Functional Area in Column A, I would like to count the distinct number of requests from column B, sum the required Man Days from Column C and sum the required cost

    The result would be:
    Collateral: 2 distinct evolution requests, 15 M/D and 150 $
    Payment Incident: 1 distinct evolution request, 15 man days and 80 $

    I have downloaded the COUNTDIFF complementary macro from the internet, it works fine for a manual task in Excel. However, I would like to integrate it to a chart (Pivot Table) and this function is not recognized among the 11 standard functionalities in Excel (NB, Sum, NB Val, etc...)

    Thanks for your help!

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

    Re: Counting Unique combinations

    Your post does not comply with Rule 2 of our Forum RULES. Don't post a question in the thread of another member -- start your own thread. If you feel it's particularly relevant, provide a link to the other thread.

+ Reply to Thread

Thread Information

Users Browsing this Thread

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

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