# Filter unique distinct values based on a date range

### Table of Contents

**Question:**I have a large list of dates and other adjacent values. I want to create a distinct list from the large list based on criteria, only values within a specific date interval.

## 1. Filter unique distinct values based on a date range

The image above shows a formula in cell E6 that extracts unique distinct values if the corresponding dates match the date range specified in cells F2 and F3.

The date range is specified in cell G1 and G2, see image above.

Array formula in cell D2:

### 1.1 How to enter an array formula

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.

### 1.2 Explaining the formula in cell D2

#### Step 1 - Which dates are later than or equal to the start date?

The less than sign and equal sign are logical operators, they allow you to compare numbers and text strings. The result are boolean values and is either TRUE or FALSE.

$F$3>=$C$3:$C$18 returns {TRUE; FALSE; ... ; TRUE}.

#### Step 2 - Which dates are earlier than or equal to the end date?

$F$2<=$C$3:$C$18 returns {TRUE; TRUE; ... ; TRUE}.

#### Step 3 - AND logic

We need to identify dates that meet both conditions, we can do that by multiplying the arrays. The parentheses allow us to control the order of operation.

($F$3>=$C$3:$C$18)*($F$2<=$C$3:$C$18) returns {1; 0; 0; ... ; 1}.

#### Step 4 - Replace 1 with the corresponding number on the same row

The IF function returns one value if the logical test is TRUE and another value if the logical test is FALSE.

IF(*logical_test*, [*value_if_true*], [*value_if_false*])

IF(($F$3>=$C$3:$C$18)*($F$2<=$C$3:$C$18), $B$3:$B$18, $E$5)

returns {12; "Unique distinct values"; ... ; 77}.

#### Step 5 - Count previous displayed values

The COUNTIF function calculates the number of cells that is equal to a condition.

COUNTIF(*range*,Â *criteria*)

COUNTIF($E$5:E5, IF(($F$3>=$C$3:$C$18)*($F$2<=$C$3:$C$18), $B$3:$B$18, $E$5))

returns {0; 1; 1; ... ; 0}.

#### Step 6 - Find first not displayed values in array

The MATCH function returns the relative position of an item in an array or cell reference that matches a specified value in a specific order.

MATCH(*lookup_value, lookup_array, [match_type]*)

MATCH(0,COUNTIF($E$5:E5, IF(($F$3>=$C$3:$C$18)*($F$2<=$C$3:$C$18), $B$3:$B$18, $E$5)), 0) returns 1.

#### Step 7 - Get value

The INDEX function returns a value from a cell range, you specify which value based on a row and column number.

INDEX(*array*,Â *[row_num]*,Â *[column_num], [area_num]*)

INDEX($B$3:$B$18, MATCH(0,COUNTIF($E$5:E5, IF(($F$3>=$C$3:$C$18)*($F$2<=$C$3:$C$18), $B$3:$B$18, $E$5)), 0)) returns 12 in cell E6.

#### Step 8 - Remove error values

The IFERROR function handles error values which the formula returns when no more values can be displayed.

IFERROR(INDEX($B$3:$B$18, MATCH(0,COUNTIF($E$5:E5, IF(($F$3>=$C$3:$C$18)*($F$2<=$C$3:$C$18), $B$3:$B$18, $E$5)), 0)), "")

## 2. Filter unique distinct values based on a date range (Excel 365)

Dynamic array formula in cell E6:

### 2.1 How to enter a dynamic array formula

The dynamic array formula is a new feature in Excel 365, you enter it as a regular formula.

### 2.2 Explaining dynamic array formula

#### Step 1 - Find dates earlier than or equal to end date

The less than sign and equal sign are logical operators, they allow you to compare numbers and text strings. The result is boolean values and the result is either TRUE or FALSE.

C3:C18<=F3 returns {TRUE; FALSE; ... ; TRUE}

#### Step 2 - Find dates later than or equal to start date

C3:C18>=F2 returns {TRUE; TRUE; ... ; TRUE}.

#### Step 3 - AND logic

Both tests must evaluate to true and to do that we need to multiply the array, in other words, apply AND logic.

Use the asterisk to multiply values or arrays.

* (asterisk) - Both logical expressions must match (AND logic)

The AND logic behind this is that

TRUE * TRUE = TRUE (1)

TRUE * FALSE = FALSE (0)

FALSE * FALSE = FALSE (0)

The parentheses control the order of operation.

(C3:C18<=F3)*(C3:C18>=F2)

returns {1; 0; ... ; 1}.

#### Step 4 - Filter values based on conditions

The FILTER function lets you extract values/rows based on a condition or criteria.Â It is in the Lookup and reference category and is only available to Excel 365 subscribers.

FILTER(array, include, [if_empty])

FILTER(B3:B18, (C3:C18<=F3)*(C3:C18>=F2)) returns {12; 77; 17; 7; 12; 12; 77}.

#### Step 5 - Extract unique distinct values based on array

The UNIQUE function lets you extract both unique and unique distinct values and also compare columns to columns or rows to rows.

UNIQUE(*array,[by_col],[exactly_once]*)

UNIQUE(FILTER(B3:B18, (C3:C18<=F3)*(C3:C18>=F2))) returns {12; 77; 17; 7}.

## Get Excel file

### Get the Excel file

unique-list-to-be-created-from-a-column-where-an-adjacent-column-is-in-a-date-range.xlsx

### Dates category

Question: I am trying to create an excel spreadsheet that has a date range. Example: Cell A1 1/4/2009-1/10/2009 Cell B1 […]

This article demonstrates how to return the latest date based on a condition using formulas or a Pivot Table. The […]

This article demonstrates how to match a specified date to date ranges. The image above shows a formula in cell […]

### Unique distinct values category

First, let me explain the difference between unique values and unique distinct values, it is important you know the difference […]

This article shows how to extract unique distinct values based on a condition applied to an adjacent column using formulas. […]

Question: I have two ranges or lists (List1 and List2) from where I would like to extract a unique distinct […]

### Excel categories

### 6 Responses to “Filter unique distinct values based on a date range”

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

Hi Oscar,

Thanks for sharing the knowledge. I've a query in case of two columns of dates and two columns of data.

Calling columns A and B as data(text), C and D as Dates(dd/mm/yy), IF column D's date is not empty and matches to the range, concatenate A & B and paste in in different sheet, ELSE column C's date(column C will always have a date unlike column D) should be taken for range calculation and then concatenate A & B cells and paste in a cell.

Please do help in regards to this query.

Best Regards,

Krish

krish,

read this post:

Sort cell values in corresponding columns

I've created a new thread for this in a forum, which has got clear explanation. It'd be great to hear from you.

https://www.excelforum.com/excel-programming-vba-macros/901407-if-condition-two-cells-with-dates-and-concatenation-of-corresponding-2-text-cells.html

Many Thanks.

Hi Oscar, your formulas are absolute legend.

Any advice on using this formula with an extra criteria.

ie. create a unique list between 2 dates and matching a certain criteria from column C

Thanks in advanced.

Mike

What if there is one unique value in particular, whose name is constant (i.e. "estimated" shows up multiple times, across multiple dates), how might I incorporate that feature into this formula? Your help would be greatly appreciated!

This formula is a rockstar, but I am having one little problem.

So, I am using this formula to try and auto-populate all the reoccurring payments in my budget for a specific range of dates my paycheck covers. I am using the days of the month, instead of the actual calendar date, so that it can easily be switched to the new pay period without much fuss.

It works amazing for January 7th through the 20th ( or 7 and 20 as I have the formula referencing), until I have a range that goes from say the 21st of January to the 3rd of February, or for mine, just 21 ($J$4) and 3 ($L$4). I can't quite pin down what the issue is and if there is an easy fix for it.

{=IFERROR(INDEX(Data!$F$2:$F$20,MATCH(0,COUNTIF($H$16:H16,IF(($L$4>=Data!$G$2:$G$20)*($J$4<=Data!$G$2:$G$20),Data!$F$2:$F$20,$H$16)),0)),"")}

Thanks in advance for your help!