## Count digits and ignore duplicates

### Question:

I have a question that I can’t seem to find an answer to:

I want to make a full count of digits 0 to 9 while ignoring duplicates in any line

B C D E

5 5 5 5

8 6 7 4

6 2 8 7

7 7 1 6

5 6 6 2

For example, with the digits shown above, my results for the count will be:

0=0; 1=1; 2=2; 3=0; 4=1; 5=5; 6=4; 7=3; 8=2; 9=0

The formula below does not work for the “5” count since it counts all the occurrences:

=COUNTIF($B$1:$E$5,5)

### Answer:

I can´t achieve the desired result for number 5. I calculated any line as "in any row" and "in any column". I guess the desired result for number 5 is a typo.

**Array formula in cell B9:**

=SUM(IF(FREQUENCY(IF(A9=$B$1:$E$5, ROW($B$1:$E$5)-MIN(ROW($B$1:$E$5))+1, ""), ROW($1:$5))>0, 1, 0)) + CTRL + SHIFT + ENTER.

Copy cell B9 and paste down as far as needed.

**Array formula in cell C9:**

=SUM(IF(FREQUENCY(IF(A9=$B$1:$E$5, COLUMN($B$1:$E$5)-MIN(COLUMN($B$1:$E$5))+1, ""), ROW($1:$4))>0, 1, 0)) + CTRL + SHIFT + ENTER.

Copy cell C9 and paste down as far as needed.

### How the formula works in cell B9

*Step 1 - Find digit in array*

=SUM(IF(FREQUENCY(IF(**A9=$B$1:$E$5**, ROW($B$1:$E$5)-MIN(ROW($B$1:$E$5))+1, ""), ROW($1:$5))>0, 1, 0))

A9=$B$1:$E$5

becomes

0={5, 5, 5, 5;8, 6, 7, 4;6, 2, 8, 7;7, 7, 1, 6;5, 6, 6, 2}

becomes

{FALSE, FALSE, FALSE, FALSE;FALSE, FALSE, FALSE, FALSE;FALSE, FALSE, FALSE, FALSE;FALSE, FALSE, FALSE, FALSE;FALSE, FALSE, FALSE, FALSE}

*Step 2 - Convert boolean array to row numbers*

=SUM(IF(FREQUENCY(**IF(A9=$B$1:$E$5, ROW($B$1:$E$5)-MIN(ROW($B$1:$E$5))+1, "")**, ROW($1:$5))>0, 1, 0))

IF(A9=$B$1:$E$5, ROW($B$1:$E$5)-MIN(ROW($B$1:$E$5))+1, "")

becomes

IF({FALSE, FALSE, FALSE, FALSE;FALSE, FALSE, FALSE, FALSE;FALSE, FALSE, FALSE, FALSE;FALSE, FALSE, FALSE, FALSE;FALSE, FALSE, FALSE, FALSE}, {1, 2, 3, 4}, "")

becomes

{"", "", "", "";"", "", "", "";"", "", "", "";"", "", "", "";"", "", "", ""}

*Step 3 - Count row numbers*

=SUM(IF(**FREQUENCY(IF(A9=$B$1:$E$5, ROW($B$1:$E$5)-MIN(ROW($B$1:$E$5))+1, ""), ROW($1:$5))**>0, 1, 0))

FREQUENCY(data_array, bins_array)*
*Calculates how often values occur within a range of values and then returns a vertical array of numbers having one more element than Bins_array

*.*

FREQUENCY(IF(A9=$B$1:$E$5, ROW($B$1:$E$5)-MIN(ROW($B$1:$E$5))+1, ""), ROW($1:$5))

becomes

FREQUENCY({"", "", "", "";"", "", "", "";"", "", "", "";"", "", "", "";"", "", "", ""}, {1; 2; 3; 4; 5})

becomes

{0; 0; 0; 0; 0}

*Step 4 - Count numbers larger than zero*

=SUM(IF(FREQUENCY(IF(A9=$B$1:$E$5, ROW($B$1:$E$5)-MIN(ROW($B$1:$E$5))+1, ""), ROW($1:$5))>0, 1, 0))

becomes

=SUM(IF({0; 0; 0; 0; 0}>0, 1, 0))

becomes

=SUM({0; 0; 0; 0; 0}) and returns 0 (zero).

### Download excel sample file

count digits in ignoring duplicates in any line.xlsx

(Excel 97-2003 Workbook *.xls)

### Functions in this article:

**IF(**logical_test,[value_if_true], [value_if_false]**) **Checks whether a condition is met, and returns one value if TRUE, and another value if FALSE

**SUM(**number1,[number2],**)
**Adds all the numbers in a range of cells

**FREQUENCY**(data_array, bins_array)*
*Calculates how often values occur within a range of values and then returns a vertical array of numbers having one more element than Bins_array

*.*

**ROW(**reference**)** returns the rownumber of a reference

**MIN(**number1,[number2]**)**

Returns the smallest number in a set of values. Ignores logical values and text

Count unique distinct values that meet multiple criteria

This post demonstrates how to build an array formula that counts unique distinct values based on criteria. What's on this […]

This article describes how to count unique distinct values. What are unique distinct values? They are all values but duplicates are […]

Count how many times a string exists in a cell range (case insensitive)

Question: How do I count how many times a word exists in a range of cells? It does not have […]

Count cells between a given value

jeyner asks: I need to count in a list the interval between the same value. Example list, 1-2-3-1-4-5-1-6-7-8-9-7-8-1 So the […]

Count unique distinct values in two columns

Question: I have values in two not adjacent columns. I want to know how many unique distinct values there are […]

Count records between two dates with multiple parameters

Sam asks in this post: Count records between two dates in excel Any chance this would work with multiple parameters. […]

Count specific text string in a cell

Question: How do I count how many times a text string exists in a cell value in Excel? Answer: The […]

Count text string in a range (case sensitive)

Question: How do I count the number of times a text string exists in a column? The text string may […]

Count unique distinct values in a filtered table

A few days ago Debra Dalgleish described how to create a Line Between Dates in Filtered List. She modified a […]

Count unique distinct values within same week, month or year

Introduction What are unique distinct values? Unique distinct values are all values but duplicates are merged into one value. Count […]

### 2 Responses to “Count digits and ignore duplicates”

### Leave a Reply

### How to comment

**How to add a formula to your comment**

<code>Insert your formula here.</code>

**Convert less than and larger than signs**

Use html character entities instead of less than and larger than signs.

< becomes < and > becomes >

**How to add VBA code to your comment**

[vb 1="vbnet" language=","]

Put your VBA code here.

[/vb]

**How to add a picture to your comment:**

Upload picture to postimage.org or imgur

Use the img tag, like this: <img src="Insert pic link here">

**Contact Oscar**

You can contact me through this contact form

I know a formulas

1*30*(5+7)/2*(0.90+0.70+0.60)/3 =

Please send a formula in my email

January 17th, 2012 at 7:26 pm

I know a formulas

1*30*(5+7)/2*(0.90+0.70+0.60)/3 =

Please send a formula in my email