Author: Oscar Cronquist Article last updated on August 24, 2021 ## 1. Filter duplicate values using criteria The following worksheet allows you to search for duplicate names using a date range (cell B1 and B2) and a condition (cell B3).

The result is displayed in cells A6 and below.

Array formula in cell A6:

=INDEX(\$G\$3:\$G\$22, SMALL(IFERROR(IF(MATCH(IF((\$E\$3:\$E\$22<=\$C\$3)*(\$E\$3:\$E\$22>=\$C\$2)*(\$F\$3:\$F\$22=\$C\$4), \$G\$3:\$G\$22, ""), IF((\$E\$3:\$E\$22<=\$C\$3)*(\$E\$3:\$E\$22>=\$C\$2)*(\$F\$3:\$F\$22=\$C\$4), \$G\$3:\$G\$22, "A"), 0)<>MATCH(ROW(\$G\$3:\$G\$22), ROW(\$G\$3:\$G\$22)), MATCH(ROW(\$G\$3:\$G\$22), ROW(\$G\$3:\$G\$22))), ""), ROW(A1)))

### 1.1 How to enter an array formula

1. Copy (Ctrl + c) above formula.
2. Double press with the left mouse button on cell A6.
3. Paste (Ctrl + v) to cell A6.
4. Press and hold CTRL + SHIFT simultaneously.
5. Press Enter once.
6. Release all keys.

Your formula now looks like this: {=array_formula}
Don't enter the curly brackets, they appear automatically.

### 1.2 Explaining formula in cell A6

#### Step 1 - Compare end date to dates

The less than sign and the equal sign are logical operaters, they let you check if the end date is larger than or equal to dates in cell range \$D\$2:\$D\$21.

The output is an array with the same size as the cell range, it contains boolean values TRUE or FALSE.

\$E\$2:\$E\$21<=\$C\$3

becomes

{41275; 41307; 41277; 41337; 41278; 41339; 41311; 41281; 0; 41374; 41307; 41306; 41276; 41337; 41278; 41339; 41311; 41281; 41282; 41374}<=41305

and returns {TRUE; FALSE; TRUE; FALSE; TRUE; FALSE; FALSE; TRUE; TRUE; FALSE; FALSE; FALSE; TRUE; FALSE; TRUE; FALSE; FALSE; TRUE; TRUE; FALSE}.

#### Step 2 - Compare start date to dates

\$E\$2:\$E\$21>=\$C\$2

becomes

{41275; 41307; 41277; 41337; 41278; 41339; 41311; 41281; 0; 41374; 41307; 41306; 41276; 41337; 41278; 41339; 41311; 41281; 41282; 41374}<=41275

and returns

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

#### Step 3 - Check condition (city)

\$F\$3:\$F\$22=\$C\$4

becomes

{"London";"Paris";"London";"Paris";"London";"Paris";"London";"Paris";0;"London";"London";"Paris";"Paris";"London";"London";"London";"London";"London";"London";"London"}="London"

and returns

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

#### Step 4 - Multiply arrays (AND Logic)

This step applies AND logic to the arrays. This means that both boolean values must be TRUE to return TRUE.

TRUE * TRUE = TRUE, FALSE* TRUE = FALSE, TRUE * FALSE= FALSE, FALSE* FALSE= FALSE.

(\$D\$2:\$D\$21<=\$B\$2)*(\$D\$2:\$D\$21>=\$B\$1)*(\$E\$2:\$E\$21=\$B\$3)

becomes

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

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

Note, boolean values are converted into their numerical equivalents when a calculation is made. TRUE = 1 and FALSE = 0 (zero).

#### Step 5 - Filter values in column F based on criteria

IF((\$D\$2:\$D\$21<=\$B\$2)*(\$D\$2:\$D\$21>=\$B\$1)*(\$E\$2:\$E\$21=\$B\$3),\$F\$2:\$F\$21,"")

#### Step 6 - Match filtered values

MATCH(IF((\$D\$2:\$D\$21<=\$B\$2)*(\$D\$2:\$D\$21>=\$B\$1)*(\$E\$2:\$E\$21=\$B\$3),\$F\$2:\$F\$21,""), IF((\$D\$2:\$D\$21<=\$B\$2)*(\$D\$2:\$D\$21>=\$B\$1)*(\$E\$2:\$E\$21=\$B\$3), \$F\$2:\$F\$21,"A")

#### Step 7 - Filter values based on being a duplicate

IF(MATCH(IF((\$D\$2:\$D\$21<=\$B\$2)*(\$D\$2:\$D\$21>=\$B\$1)*(\$E\$2:\$E\$21=\$B\$3),\$F\$2:\$F\$21,""), IF((\$D\$2:\$D\$21<=\$B\$2)*(\$D\$2:\$D\$21>=\$B\$1)*(\$E\$2:\$E\$21=\$B\$3), \$F\$2:\$F\$21,"A"), 0)<>MATCH(ROW(\$F\$2:\$F\$21), ROW(\$F\$2:\$F\$21)), MATCH(ROW(\$F\$2:\$F\$21), ROW(\$F\$2:\$F\$21)))

#### Step 8 - Remove error values

IFERROR(IF(MATCH(IF((\$D\$2:\$D\$21<=\$B\$2)*(\$D\$2:\$D\$21>=\$B\$1)*(\$E\$2:\$E\$21=\$B\$3),\$F\$2:\$F\$21,""), IF((\$D\$2:\$D\$21<=\$B\$2)*(\$D\$2:\$D\$21>=\$B\$1)*(\$E\$2:\$E\$21=\$B\$3), \$F\$2:\$F\$21,"A"), 0)<>MATCH(ROW(\$F\$2:\$F\$21), ROW(\$F\$2:\$F\$21)), MATCH(ROW(\$F\$2:\$F\$21), ROW(\$F\$2:\$F\$21))), "")

#### Step 9 - Extract k-th smallest row number

SMALL(IFERROR(IF(MATCH(IF((\$D\$2:\$D\$21<=\$B\$2)*(\$D\$2:\$D\$21>=\$B\$1)*(\$E\$2:\$E\$21=\$B\$3),\$F\$2:\$F\$21,""), IF((\$D\$2:\$D\$21<=\$B\$2)*(\$D\$2:\$D\$21>=\$B\$1)*(\$E\$2:\$E\$21=\$B\$3), \$F\$2:\$F\$21,"A"), 0)<>MATCH(ROW(\$F\$2:\$F\$21), ROW(\$F\$2:\$F\$21)), MATCH(ROW(\$F\$2:\$F\$21), ROW(\$F\$2:\$F\$21))), ""), ROW(A1))

#### Step 10 - Get value based on row number

INDEX(\$F\$2:\$F\$21, SMALL(IFERROR(IF(MATCH(IF((\$D\$2:\$D\$21<=\$B\$2)*(\$D\$2:\$D\$21>=\$B\$1)*(\$E\$2:\$E\$21=\$B\$3),\$F\$2:\$F\$21,""), IF((\$D\$2:\$D\$21<=\$B\$2)*(\$D\$2:\$D\$21>=\$B\$1)*(\$E\$2:\$E\$21=\$B\$3), \$F\$2:\$F\$21,"A"), 0)<>MATCH(ROW(\$F\$2:\$F\$21), ROW(\$F\$2:\$F\$21)), MATCH(ROW(\$F\$2:\$F\$21), ROW(\$F\$2:\$F\$21))), ""), ROW(A1)))

## 2. Filter duplicate values using criteria - Excel 365 Formula in cell B7:

=LET(z, FILTER(G3:G22, (C2<=E3:E22)*(C3>=E3:E22)*(C4=F3:F22)), FILTER(z, MATCH(z, z, 0)<>SEQUENCE(ROWS(z))))

### 2.1 Explaining formula

#### Step 1 - Compare dates to start date

The less than character and the equal sign combined check if the dates are earlier or equal to the start date.

C2<=E3:E22

#### Step 2 - Compare dates to end date

The greater than character and the equal sign combined check if the dates are later or equal to the start date.

C3>=E3:E22

#### Step 3 - Check condition

The equal sign checks if the condition is equal to values in cell range F3:F22.

C4=F3:F22

#### Step 4 - Multiply arrays (AND logic)

The asterisk allows you to multiply arrays. The arrays contain either TRUE or FALSE. Multiplying boolean values TRUE or FALSE creates AND - logic meaning both values must be TRUE to return TRUE.

In other words, all three conditions must be met in order to return TRUE.

(C2<=E3:E22)*(C3>=E3:E22)*(C4=F3:F22)

#### Step 5 - Filter values based on criteria

The FILTER function filters values in a given cell range based on a condition or criteria.

FILTER(G3:G22, (C2<=E3:E22)*(C3>=E3:E22)*(C4=F3:F22))

#### Step 6 - Match filtered values

The MATCH function returns a number representing the relative position of an item in an array or cell range.

MATCH(z, z, 0)

#### Step 7 - Create sequence based on the number of filtered values

The SEQUENCE function returns a sequence of numbers.

SEQUENCE(rows, [columns], [start], [step])

SEQUENCE(ROWS(z))

#### Step 8 - Check for duplicates

The less than and greater than characters return TRUE if the numbers don't match indicating that the value is a duplicate.

MATCH(z, z, 0)<>SEQUENCE(ROWS(z))

#### Step 9 - Filter duplicate values

FILTER(z, MATCH(z, z, 0)<>SEQUENCE(ROWS(z)))

### Get the Excel file Extract-duplicates-using-conditionsv3.xlsx