## How to count unique distinct values based on a date

The array formula in cell D3 calculates the number of unique distinct items based on the given date in column B. Unique distinct values are all values but duplicates are merged into one value.

Example, there are five items on date 1/5/2010 in the table above. 1150, 1126, 1131, 1131 and 1126, however there are only three unique distinct items 1150, 1126 and 1131 and that number is what the formula returned in cell D3.

**Array formula in D3:**

To enter an array formula, type the formula in a cell then press and hold CTRL + SHIFT simultaneously, now press Enter once. Release all keys.

The formula bar now shows the formula with a beginning and ending curly bracket telling you that you entered the formula successfully. Don't enter the curly brackets yourself.

Copy cell D3 and paste it down as far as needed.

### Explaining formula in cell D3

#### Step 1 - Calculate alphabetical rank

The COUNTIF function counts values based on a condition or criteria, in this case I use the ampersand to concatenate a less than sign. This will return a number representing the rank in an alphabetically sorted list.

COUNTIF($C$3:$C$11, "<"&$C$3:$C$11)

becomes

COUNTIF({1150;1126;1131;1131;1126;1150;1150;1131;1131},{"<1150";"<1126";"<1131";"<1131";"<1126";"<1150";"<1150";"<1131";"<1131"})

and returns

{6;0;2;2;0;6;6;2;2}

#### Step 2 - Extract numbers based on date

The IF function has three arguments, the first one must be a logical expression. If the expression evaluates to TRUE then one thing happens (argument 2) and if FALSE another thing happens (argument 3).

IF(B3=$B$3:$B$11, COUNTIF($C$3:$C$11, "<"&$C$3:$C$11), "")

becomes

IF(40183={40183; 40183; 40183; 40183; 40183; 40184; 40184; 40184; 40184},COUNTIF($C$3:$C$11,"<"&$C$3:$C$11),"")

becomes

IF({TRUE; TRUE; TRUE; TRUE; TRUE; FALSE; FALSE; FALSE; FALSE},COUNTIF($C$3:$C$11,"<"&$C$3:$C$11),"")

and returns

{6;0;2;2;0;"";"";"";""}.

#### Step 3 - Cacluate frequency

The FREQUENCY function calculates how often values occur in a range.

FREQUENCY(IF(B3=$B$3:$B$11, COUNTIF($C$3:$C$11, "<"&$C$3:$C$11), ""), (COUNTIF($C$3:$C$11, "<"&$C$3:$C$11))

becomes

FREQUENCY({6; 0; 2; 2; 0; ""; ""; ""; ""},{6; 0; 2; 2; 0; 6; 6; 2; 2})

and returns

{1;2;2;0;0;0;0;0;0;0}

#### Step 4 - Is number larger than 0 (zero)?

The value is unique distinct if the corresponding number in the array is larger than 0 (zero).

FREQUENCY(IF(B3=$B$3:$B$11, COUNTIF($C$3:$C$11, "<"&$C$3:$C$11), ""), (COUNTIF($C$3:$C$11, "<"&$C$3:$C$11))>0

becomes

{1;2;2;0;0;0;0;0;0;0}>0

and returns

{TRUE; TRUE; TRUE; FALSE; FALSE; FALSE; FALSE; FALSE; FALSE; FALSE}

#### Step 5 - Convert boolean values

The SUM function can't sum boolean value so we must convert them into their numerical equivalents.

--(FREQUENCY(IF(B3=$B$3:$B$11, COUNTIF($C$3:$C$11, "<"&$C$3:$C$11), ""), (COUNTIF($C$3:$C$11, "<"&$C$3:$C$11)))>0)

becomes

--({TRUE; TRUE; TRUE; FALSE; FALSE; FALSE; FALSE; FALSE; FALSE; FALSE})

and returns

{1;1;1;0;0;0;0;0;0;0}

#### Step 6 - Sum numbers

The SUM function adds numbers in the array and returns a total.

SUM(--(FREQUENCY(IF(B3=$B$3:$B$11, COUNTIF($C$3:$C$11, "<"&$C$3:$C$11), ""), (COUNTIF($C$3:$C$11, "<"&$C$3:$C$11)))>0))

becomes

SUM({1;1;1;0;0;0;0;0;0;0})

and returns 3.

### Count values category

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

This article explains how to count cells highlighted with Conditional Formatting (CF). The image above shows data in cell range […]

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

This article demonstrates formulas that calculate the number of cells between two values, the first scenario involves two search values […]

Formula in C12: =SUM(1/COUNTIF($B$3:$B$8, $B$3:$B$8))+SUM(IF(COUNTIF($B$3:$B$8, $D$3:$D$8)=0, 1/COUNTIF($D$3:$D$8, $D$3:$D$8), 0)) How to create an array formula Double press with left mouse […]

This article demonstrates a formula that counts unique distinct values filtered from an Excel defined Table. Debra Dalgleish described in […]

The array formula in cell E3 counts unique distinct items for all dates within the same week. Example, week 2 […]

This article demonstrates how to construct a formula that counts unique distinct values based on a condition. The image above […]

This article demonstrates formulas that count values in cell based on a delimiting character. The image above shows a formula […]

The MEDIAN function lets you count overlapping dates between two date ranges. If you have more than two date ranges […]

This post demonstrates a formula in cell D16 that counts overlapping dates across multiple date ranges. The date ranges are […]

davidlim asks: re: Count records between two dates and a criterion based on the example, i was looking for 1 […]

This article demonstrates techniques on how to count cells based on the background color. I will also demonstrate user defined […]

The formula in cell E16 counts the number of cells between value B and H, Value B is in cell B3 […]

In the previous post I explained how to count overlapping dates comparing a single date range against multiple date ranges. […]

This article demonstrates ways to count contiguous values in a column, in other words, values that repeat and are adjacent. […]

Question: My issue is that I get the date in this format: 7/23/2011 7:00:00 AM I am trying to count […]

NETWORKDAYS function returns the number of whole workdays between two dates, however the array formula I am going to demonstrate […]

Janib Soomro asks: In A column, there are dates in mmddyyy format and in B column, there are two variables […]

## Functions in this article

More than 1300 Excel formulas

## Excel formula categories

## Excel categories

### 10 Responses to “How to count unique distinct values based on a date”

### 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

Paste image link to your comment.

**Contact Oscar**

You can contact me through this contact form

How would I modify this formula to then allow me to filter another row of data?

For example, if there was a yes / no entry in column e, that would then further pair down the entries from 3 to between 3-0. Is it possible to do this with this formula? The formula works great for counting the unique occurrencies based on two columns, but I would like to add a third column requirement that I can move around to then filter information as needed.

Thanks,

Dave

David,

Formula in cell D3:

[…] try this How to count unique distinct occurrences for each date in excel | Get Digital Help - Microsoft Excel… […]

Is there a way to subtotal the unique distinct values on each date with counting each date only once?

While failing to apply the above formula on my data, i copied the above example and function and the result i get is 1.

What am i doing wrong?

Thanos,

Did you enter the formula as an array formula?

Are there curly brackets around your formula in the formula bar?

Like this:

{=SUM(--(FREQUENCY(IF(B3=$B$3:$B$11, COUNTIF($C$3:$C$11, "<"&$C$3:$C$11), ""), (COUNTIF($C$3:$C$11, "<"&$C$3:$C$11)))>0))}

Don't enter those characters yourself, they appear if you successfully entered the array formula.

Just as done by one day. How can it be done with number of days. I want to get unique numbers whose days difference is 30.

Thank you very much. It helps my problem. :)

If I want to skip blank field for count, how would I do that?

May I know , what if I want to ignored "BLANKS" for unique count?