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

becomes

44581>={44573; 44588; 44566; 44584; 44565; 44578; 44580; 44579; 44588; 44584; 44588; 44569; 44588; 44580; 44577; 44571}

and returns

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

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

$F$2<=$C$3:$C$18

becomes

44571<={44573; 44588; 44566; 44584; 44565; 44578; 44580; 44579; 44588; 44584; 44588; 44569; 44588; 44580; 44577; 44571}

and returns

{TRUE; TRUE; FALSE; TRUE; FALSE; TRUE; TRUE; TRUE; TRUE; TRUE; TRUE; FALSE; TRUE; 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)

becomes

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

and returns

{1; 0; 0; 0; 0; 1; 1; 1; 0; 0; 0; 0; 0; 1; 1; 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)

becomes

IF({1; 0; 0; 0; 0; 1; 1; 1; 0; 0; 0; 0; 0; 1; 1; 1}, $B$3:$B$18, $E$5)

becomes

IF({1; 0; 0; 0; 0; 1; 1; 1; 0; 0; 0; 0; 0; 1; 1; 1}, {12; 77; 42; 12; 19; 77; 17; 7; 12; 19; 11; 17; 2; 12; 12; 77}, "Unique distinct values")

and returns

{12; "Unique distinct values"; "Unique distinct values"; "Unique distinct values"; "Unique distinct values"; 77; 17; 7; "Unique distinct values"; "Unique distinct values"; "Unique distinct values"; "Unique distinct values"; "Unique distinct values"; 12; 12; 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))

becomes

COUNTIF($E$5:E5, {12; "Unique distinct values"; "Unique distinct values"; "Unique distinct values"; "Unique distinct values"; 77; 17; 7; "Unique distinct values"; "Unique distinct values"; "Unique distinct values"; "Unique distinct values"; "Unique distinct values"; 12; 12; 77})

becomes

COUNTIF("Unique distinct values", {12; "Unique distinct values"; "Unique distinct values"; "Unique distinct values"; "Unique distinct values"; 77; 17; 7; "Unique distinct values"; "Unique distinct values"; "Unique distinct values"; "Unique distinct values"; "Unique distinct values"; 12; 12; 77})

and returns

{0; 1; 1; 1; 1; 0; 0; 0; 1; 1; 1; 1; 1; 0; 0; 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)

becomes

MATCH(0,{0; 1; 1; 1; 1; 0; 0; 0; 1; 1; 1; 1; 1; 0; 0; 0}, 0)

and 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))

becomes

INDEX($B$3:$B$18, 1)

and 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

becomes

{44573; 44588; 44566; 44584; 44565; 44578; 44580; 44579; 44588; 44584; 44588; 44569; 44588; 44580; 44577; 44571}<=44581

and returns

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

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

C3:C18>=F2

becomes

{44573; 44588; 44566; 44584; 44565; 44578; 44580; 44579; 44588; 44584; 44588; 44569; 44588; 44580; 44577; 44571}>=44571

and returns

{TRUE; TRUE; FALSE; TRUE; FALSE; TRUE; TRUE; TRUE; TRUE; TRUE; TRUE; FALSE; TRUE; 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)

becomes

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

and returns

{1; 0; 0; 0; 0; 1; 1; 1; 0; 0; 0; 0; 0; 1; 1; 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))

becomes

FILTER(B3:B18, {1; 0; 0; 0; 0; 1; 1; 1; 0; 0; 0; 0; 0; 1; 1; 1})

and 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)))

becomes

UNIQUE({12; 77; 17; 7; 12; 12; 77})

and returns {12; 77; 17; 7}.

## Get Excel file

### 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 […]

The image above demonstrates an array formula in cell E4 that searches for the closest date in column A to the […]

adam asks: Hi, I have a situation where I want to count if this value is duplicate and if it […]

This article demonstrates formulas that show if a date range is overlapping another date range. The second section shows how […]

This article demonstrates a formula that extracts unique distinct records/rows for a given month specified in cell C2, see the […]

This article explains how to find the smallest and largest value using two conditions. In this case they are date […]

I found an old post that I think is interesting to write about today. Think of two overlapping ranges, it […]

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

The array formula in cell D4 extracts the start dates for date ranges in cell range B3:B30, the array formula […]

This article demonstrates a formula that points out row numbers of records that overlap the current record based on a […]

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

Question: How do I create a list of dates with blanks between each quarter? (Q1, Q2, Q3 and Q4) Answer: […]

Question: How to create unique distinct year and months from a long date listing (column A)? You can find the […]

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

The array formula in cell B3 creates a list of dates based on the date ranges displayed in D3:E7, it […]

This article demonstrates a formula that returns a date range that a date falls under, cell C3 above contains the […]

This article demonstrates how to calculate dates in a given date range (cells B13 and B14) that don't overlap the […]

### Unique distinct values category

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

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

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

The array formula in cell D3 extracts unique distinct values sorted A to Z, from column B to column D. […]

Anura asks: Is it possible to extend this by matching items that meet a criteria? I have a list of […]

Question: How do I extract a unique distinct list from three ranges or lists? The ranges are not necessarily adjacent […]

This article demonstrates formulas that extract unique distinct values and ignore blank empty cells. Table of contents Extract a unique […]

Question: I have cell values spanning over several columns and I want to create a unique list from that range. […]

Question: How do I create a unique distinct list where other columns meet two criteria using excel array formula? Answer: […]

This article demonstrates formulas that extract sorted unique distinct values from a cell range containing also blanks. Unique distinct values […]

This article demonstrates two formulas that extract distinct values from a filtered Excel Table, one formula for Excel 365 subscribers […]

Question: How do I create a unique distinct list where adjacent cell values contain a search string? AA102 CA AA103 […]

Filtering unique distinct text values and sorting them based on the sum of adjacent values can easily be done by […]

EEK asks: I am looking for the same formula on this page, but targeting a range of MxN (spanning multiple […]

This article demonstrates a formula that extracts unique distinct records/rows for a given month specified in cell C2, see the […]

Question: How do I create a unique distinct list from a column sorted A to Z using array formula? Array […]

The image above demonstrates a formula in cell F3 that extracts unique distinct values from column B if they contain […]

Question: How to create unique distinct year and months from a long date listing (column A)? You can find the […]

Question: I want a unique distinct list to be created from a column where an adjacent column has text cell […]

## Functions in this article

More than 1300 Excel formulas

## Excel formula categories

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