Is there a formula to count unique entries in a range of cells, and possible ignore certain predefined entries

I would like to create a formula to accomplish a task, I am not sure how to do it.


Basically, I will have cells A1-A31, with 1 corresponding with a day of the month.


Each cell A1-A31 will contain HEX data, in the form of a name (ie: John Smith) I would like another cell such as A5 to count the unique entries within the range of A1-A31.


If I can be pointed in the right direction, I can figure out for corresponding cells.


Basically it will look like this (plus other calculations, I already achieved)


DATE NAME TOTAL_CASES

1 John Smith 1

2 John Smith 1

3 Roxy Jones 2

4 Huang Nguyen 3

5 Huang Nguyen 3

6 Bradly Katz 4

7 Linda Schutlz 5

8 off 5 <--- possible addition step of ignoring "off"

9 Julie Dawgie 6



Additionally, if there is a way to count the "unique entries" in the given range, it it possible to IGNORE an item, such as the word "off" and/or "vacation?

Posted on Feb 8, 2014 7:46 PM

Reply
23 replies

Feb 8, 2014 10:42 PM in response to MikeCWest

In the description above, when you say A5 to count unique entries, you really mean the TOTAL_CASES column right? That is what I get from your table, TOTAL_CASES (I'll call it column C) cells are adding 1 each time it comes to a new name.


Couple different ways to do this depending on how the NAME column is setup.


In your example, all the duplicate names are next to each other. If this is always the case (or if you can sort the NAME column and don't care it will mess up the date column), then Option A. Otherwise, Option B, which is more complicated to explain.


Option A:


Put this formula in C2 and fill down.

=IF(OR(B2="off",B2="vacation",B2="",B2=B1),C1,SUM(C1,1))

Says if B2 is off, vacation, empty, or equal to the cell above it, then don't add 1. Otherwise, add 1.


User uploaded file



Option B:


Put this formula in C2 and fill down.

=COUNTIF(B,B2)

Says count how many duplicates for each name.


Put this formula in D2 and fill down.

=COUNTIF(C,ROW()−1)÷(ROW()−1)


Says.. well.. I need to explain with specifics.


Cell D2 says how many names have no duplicates.

In your table, 5 (Roxy, Brad, Linda, off, Julie), then 5/1 = 5 unique names.


Cell D3 says how many names have exactly 1 duplicate and divide that by 2.

In your table, 4 (John, John, Huang, Huang), then 4/2 = 2 unique names.


Cell D4 says how many names have exactly 2 duplicates and divide that by 3.

In your table 0.

etc...


Add a footer row to the table and put this in the footer cell for column D.

=SUM(D)−IF(COUNTIF(B,"off"),1,0)−IF(COUNTIF(B,"vacation"),1,0)


Says SUM up the unique names, but minus 1 if there are ANY number of offs, and minus 1 if there are ANY number of vacations.


User uploaded file


Disclaimer. I 'think' this works.


My solution appears to work. I tried just about everything. But, looks like SGIII had a simpler solution. Nice one.


Message was edited by: ronniefromcalifornia

Feb 9, 2014 12:48 AM in response to MikeCWest

Hi Mike,


There are four names that are unique within your sample (not counting "off"): Roxy, Linda, Bradley and Julie. But I suspect you want a count of distinct names (6, again not counting "off".


Here's an example, using a method similar to that proposed by SG, but that also constructs an index useful in retrieving the list of distinct names for use in a separate table:

User uploaded file

Column C of Data contains the count. It uses this formula, enterec in C2 and filled down to C11:


=IF(OR(B="off",B="vacation",COUNTIF($B$2:B2,B)>1),"",MAX($C$1:C1)+1)


If the total is needed elsewhere on the table, it can be retrieved using the formula in D2:


=MAX(C)


The index to names created in column C can be used to retrieve those names in a Summary table, using a LOOKUP formula such as the one in A2, and filled down:


=IF(ROW()-1>MAX(Data :: C),"",LOOKUP(ROW()-1,Data :: C,Data :: B))


The IF part of this formula is used to shut it off when the last name has been retrieved, preventing LOOKUP from repeating the last value retrieved in all rows below row 7.


Other data can be retrieved from the same row of the data table, or as done here, can be calculated from data on that table using formulas referencing that data, such as this one, entered in B2 and filled down:


=IF(LEN(A)<1,"",COUNTIF(Data :: B,A))


As above, the IF condition is used to keep the appearance of blank cells where there is no data to be retrieved of=r calculated.


Regards,

Barry

Feb 9, 2014 5:47 AM in response to MikeCWest

@Ronnie and @Barry


Learned a lot from your posts. Like you I'm not sure if this is what the OP wants, but I often find myself in a situation where I want to extract and list distinct values. Barry's index column approach is ingenious and allows you to stick to Numbers proper. If you want to "cheat" and use AppleScript (and you have Numbers 3.1) I've found this Automator Service (Dropbox download) convenient. All I have to do is select the cells I want to extract duplicates form, make a menu pick (could even be a keyboard shortcut), and paste (command-v) the list of distinct values where wanted. On my machine it looks like this:


User uploaded file




More details are in this thread in case you want to check it out before downloading. (If you download and get a warning when you double-click to install, go to System Preferences > Security & Privacy and click 'Download anyway'.)


SG

Feb 9, 2014 9:16 AM in response to ronniefromcalifornia

Yes, the "total cases" is located is what I meant. I am not sure where I was going with A5, but my poor diagram apparently helped explain. I believe it it going to work for what I need. SG's solution was perfect, its a fairly simple form that I am trying to make, but that one column has been driving me crazy. I previously had it in MS Excel, but I think Apple Numbers looks much nicer.


The sheet basically counts the number of days that I worked, the number of "jobs" worked. It then takes the number of "sucessful" days, and "sucessful" cases and gives an average %. the calculations were easy math.


I have been manually counting the numbers in the "total jobs" column for years, and finally decided to combat that issue.


Thanks to all who promptly replied, and solved my issue much quicker than I would have expected!

Feb 10, 2014 9:01 AM in response to MikeCWest

OK,


I am having a new struggle. I have the formula ALMOST doing what I want. In the same scenario, jobs are worked daily, the formula now correctly counts the number of "jobs" worked.


If a job is sucessful, a "Y" is inserted into column C, I need the total number of sucessful jobs.


It works, but only if the first day of the "job" was a sucess. If fail the first day, but suceed on a subsequent try, then it fails to count correctly.

The charts below have an extra column and row addedd to show the Row numbers and column letters

My column "G" Forumula is:" =IF(AND(D4=1, E4="y"), H3+1, H3+0)"



A

B

C

D

E

F

G

H

I

J

K

1

Date

Name

hidden counter

Success

Days successful

Days Worked

jobs successful

jobs worked

% by job

Combined%

Notes

2

HIDE


0


0

0

0

0




3

1

john

1

Y

1

1

1

1

100.000%

100.000%


4

2

John

0

N

1

2

1

1

100.000%

75.000%

<—counted only once in “jobs successful as expected

5

3

off

0

off

1

2

1

1

100.000%

75.000%


6

4

Bill

1

N

1

3

1

2

50.000%

41.667%


7

5

bill

0

Y

2

4

1

2

50.000%

50.000%

note that job is not counted as successful

8

6

Fred

1

Y

3

5

2

3

66.667%

63.333%


9

7

John

0

N

3

6

2

3

66.667%

58.333%


10

8

Fred

0

Y

4

7

2

3

66.667%

61.905%






If counted correctly, it should look like this:



A

B

C

D

E

F

G

H

I

J

K

1

Date

Name

hidden counter

Success

Days successful

Days Worked

jobs successful

jobs worked

% by job

Combined%

Notes

2



0


0

0

0

0




3

1

john

1

Y

1

1

1

1

100.000%

100.000%


4

2

John

0

N

1

2

1

1

100.000%

75.000%

<—counted only once in “jobs successful as expected

5

3

off

0

off

1

2

1

1

100.000%

75.000%


6

4

Bill

1

N

1

3

1

2

50.000%

41.667%


7

5

bill

0

Y

2

4

2

2

100.000%

75.000%

jobs successful shown correctly with manual input

8

6

Fred

1

Y

3

5

3

3

100.000%

80.000%


9

7

John

0

N

3

6

3

3

100.000%

75.000%


10

8

Fred

0

Y

4

7

3

3

100.000%

78.571%


Feb 10, 2014 6:50 PM in response to SGIII

The formula only appears to count the total number of "Y", but should be ignoring a second "Y" for that name.


Date

Claimant Name

hidden counter

sucessful?

days sucessful

days worked

days sucessful

days worked

Case%

Overall%



0


0

0

1

0



1

Brian

1

Y

1

1

2

1

200.000%

150.000%

2

Brian

0

Y

2

2

2

1

200.000%

150.000%

3

Octavio

1

N

2

3

2

2

100.000%

83.333%

4

Vicki

1

N

2

4

2

3

66.667%

58.333%

5

Octavio

0

N

2

5

2

3

66.667%

53.333%

6

Sara

1

N

2

6

2

4

50.000%

41.667%

7

Sara

0

N

2

7

3

4

75.000%

51.786%

8

Delfino

1

Y

3

8

4

5

80.000%

58.750%

9

Delia

1

Y

4

9

5

6

83.333%

63.889%

10

Vicki

0

Y

5

10

6

6

100.000%

75.000%

11

Cesar

1

Y

6

11

7

7

100.000%

77.273%

12

Larry

1

Y

7

12

8

8

100.000%

79.167%

13

Larry

0

Y

8

13

8

8

100.000%

80.769%


when counted correctly, it would look like:


Date

Claimant Name

hidden counter

Was Video Obtained?

Days Video Obtained

Days Worked

Cases Video Obtained

Cases Worked

Case%

Overall%



0


0

0

0

0



1

Brian

1

Y

1

1

1

1

100.000%

100.000%

2

Brian

0

Y

2

2

1

1

100.000%

100.000%

3

Octavio

1

N

2

3

1

2

50.000%

58.333%

4

Vicki

1

N

2

4

1

3

33.333%

41.667%

5

Octavio

0

N

2

5

1

3

33.333%

36.667%

6

Sara

1

N

2

6

1

4

25.000%

29.167%

7

Sara

0

N

2

7

1

4

25.000%

26.786%

8

Delfino

1

Y

3

8

2

5

40.000%

38.750%

9

Delia

1

Y

4

9

3

6

50.000%

47.222%

10

Vicki

0

Y

5

10

4

6

66.667%

58.333%

11

Cesar

1

Y

6

11

5

7

71.429%

62.987%

12

Larry

1

Y

7

12

6

8

75.000%

66.667%

13

Larry

0

Y

8

13

6

8

75.000%

68.269%

Feb 10, 2014 8:00 PM in response to SGIII

>>>

However, it depends on your 'hidden counter' column. Shouldn't that be 1 for Vicki?


SG

>>>


No, Vicki is not "1", because that counter was for the "unique names" (for use in column H calculation. and she is above on row 6. The cases worked column counts perfectly. What I am trying to accomplish, is to count the number of cases, out of the total cases, where video was obtained. that is where case% comes in.


Maybe I should not be using that counter? I am totally lost on how to go about it.



It is common for the days worked to be non-consectutive, with other cases in between. I am sure you can tell that I don't work as a computer programmer!

Feb 10, 2014 8:29 PM in response to MikeCWest

Ah, I see. The hidden counter is 1 if that person is not already listed somewhere.


So why do you want the Cases Video Obtained to increase with the second listing of Vicki? Is that because it's a new case?


If so, you may find a Case ID column will be useful. Then you could set up another hidden counter. Or revisit Barry's approach above.


If it is indeed because the second listing of Vicki is a new case, then maybe you could add the column and post again, and someone will be able to help you get what you want.


SG

Feb 10, 2014 9:30 PM in response to SGIII

>>>>

So why do you want the Cases Video Obtained to increase with the second listing of Vicki? Is that because it's a new case?

>>>>


The reason why, is that on the first day, case video was NOT obtained, but was obtained on the second day. (and in other cases may be on the 3rd , 4th, etc... day or possibly not obtained at all.)


As far as the names go, the cell will have the persons full name in it, like "Julio Valdez", it is not likely that I would work two "Julio Valdez" in one month, but if it ever happens I add middle initial. I have the sheet set up for 31 days, and plan to use a new sheet each month.


Basically, in the total month the desired result is to get video of each person, at least once per month. That is why the case% exists. There is the seperate per day calculation.


The forumula in column C is the one you created for me. ( =IF(COUNTIFS($B$2:B2,B2,$B$2:B2,"<>" & "off")=1,1,0) )

Feb 11, 2014 12:41 AM in response to MikeCWest

Hi Mike,


Here's my example. I've left out data not germane to the count in column G.

User uploaded file


I don't see a use for row 2, so I've removed it. If you need that row for some purpose, just change the 1 in each of the cell references 2, and place both the formulas in row 3.


E2: =IF(D="Y",MAX($E$1:E1)+1,MAX($E$1:E1))


H2: =IF(COUNTIFS($B$2:B2,B,$D$2:D2,"Y")=1,MAX($H$1:H1)+1,MAX($H$1:H1))


Regards,

Barry

Feb 11, 2014 8:27 AM in response to Barry

Barry,


I'm a bit more lost now.


"cases video was obtained" is supposed to be G, but you show it in H.


As far as Vicki goes, yes, the Y in row 10 should increase the count in G because it is the first time that Vicki had a Y next to her.


My row 2 which contains the 0's is for simple formulas (cell above plus 1), and in another case (cell above plus column C in current row)


Your E2 formula accomplishes the same task as my current formula in column E.


The cases wher video was obtained, still does not seem to work right. Maybe I'm missing something. I try it on several different revisions of my sheet, and each produces different results, none of which seem to be what it should.

This thread has been closed by the system or the community team. You may vote for any posts you find helpful, or search the Community for additional answers.

Is there a formula to count unique entries in a range of cells, and possible ignore certain predefined entries

Welcome to Apple Support Community
A forum where Apple customers help each other with their products. Get started with your Apple Account.