View Single Post
  #3   Report Post  
Posted to microsoft.public.excel.worksheet.functions
Ron Rosenfeld Ron Rosenfeld is offline
external usenet poster
 
Posts: 5,651
Default Counting unique numbers

On Mon, 10 Aug 2009 21:07:01 -0700 (PDT), Juan Marin
wrote:

Hello everyone,

I have a large set of data that has in one column, the company id
which repeats on consecutive rows for each year in the dataset. Then
in the next column, there's the ID of each segment within the company
(a number). I need to count for each company code, how many segments
(unique numbers) are there. The data for a small sample looks like
this:

COMP-ID SEG-ID
1001 1
1001 1
1001 1
1003 1
1003 1
1003 1
1003 1
1004 3
1004 4
1004 5
1004 3
1004 4
1004 5
1004 3

in this case I would need to generate a list like this

1001 1
1003 1
1004 3

which means that company 1001 has 1 segment, 1003 has 1 segment and
company 1004 has 3 segments (segments 3, 4 and 5).

I hope anybody can shed some light on how to tackle this one because I
haven't been able to figure something out. Thanks in advance,

Juan Marin


Add a column to your data.

If your has the column labels in A1:B1, and the data starts in A2, then

C1: Unique Segs
C2: =IF(SUMPRODUCT(($A$2:$A2=A2)*($B$2:$B2=B2))1,0,1)

Fill down as far as needed.

Then Insert/Pivot Table.

COMP-ID to Row area
Unique Segs to Values or Data area

Make sure your "Unique Segs" value field setting is set to do a SUM
--ron