Author: Oscar Cronquist Article last updated on November 26, 2018

Array formula in D2:

=INDEX($A$2:$A$21, MATCH(SMALL(IF(COUNTIF($B$2:$B$21, $B$2:$B$21)>1, COUNTIF($A$2:$A$21, "<"&$A$2:$A$21), ""),ROWS($A$1:A1)), COUNTIF($A$2:$A$21, "<"&$A$2:$A$21), 0))

Array formula in E2:

=INDEX($B$2:$B$21, MATCH(SMALL(IF(COUNTIF($B$2:$B$21, $B$2:$B$21)>1, COUNTIF($A$2:$A$21, "<"&$A$2:$A$21), ""),ROWS($A$1:A1)), COUNTIF($A$2:$A$21,"<"&$A$2:$A$21), 0))

Explaining formula in cell D2

Step 1 - Identify duplicates

The COUNTIF function counts values based on a condition or criteria.

COUNTIF($B$2:$B$21, $B$2:$B$21)>1

becomes

COUNTIF({"BB"; "VV"; "WW"; "BB"; "DD"; "KK"; "YY"; "UU"; "LL"; "WW"; "PP"; "CC"; "VV"; "MM"; "EE"; "WW"; "KK"; "TT"; "II"; "PP"}, {"BB"; "VV"; "WW"; "BB"; "DD"; "KK"; "YY"; "UU"; "LL"; "WW"; "PP"; "CC"; "VV"; "MM"; "EE"; "WW"; "KK"; "TT"; "II"; "PP"})>1

becomes

{2;2;3;2; 1;2;1;1;1; 3;2;1;2;1;1;3; 2;1;1;2}>1

and returns

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

Step 2 - Convert boolean values

The IF function returns a value based on a logical expression, TRUE returns argument2 and FALSE returns argument3.

IF(COUNTIF($B$2:$B$21, $B$2:$B$21)>1, COUNTIF($A$2:$A$21, "<"&$A$2:$A$21), "")

becomes

IF({TRUE; TRUE; TRUE; TRUE; FALSE; TRUE; FALSE; FALSE; FALSE; TRUE; TRUE; FALSE; TRUE; FALSE; FALSE; TRUE; TRUE; FALSE; FALSE; TRUE}, COUNTIF($A$2:$A$21, "<"&$A$2:$A$21), "")

The COUNTIF function returns a rank number indicating the position if the list were sorted, "<" is concatenated with A$2:$A$21 to make the COUNTIF function behave in this way.

IF({TRUE; TRUE; TRUE; TRUE; FALSE; TRUE; FALSE; FALSE; FALSE; TRUE; TRUE; FALSE; TRUE; FALSE; FALSE; TRUE; TRUE; FALSE; FALSE; TRUE}, COUNTIF($A$2:$A$21, "<"&$A$2:$A$21), "")

becomes

IF({TRUE; TRUE; TRUE; TRUE; FALSE; TRUE; FALSE; FALSE; FALSE; TRUE; TRUE; FALSE; TRUE; FALSE; FALSE; TRUE; TRUE; FALSE; FALSE; TRUE}, {7; 11; 8; 19; 16; 17; 15; 10; 9; 0; 4; 18; 14; 2; 1; 13; 6; 2; 12; 4}, "")

and returns

{7;11;8; 19;"";17;"";"";""; 0;4;"";14;""; "";13;6;""; "";4}

Step 3 - Extract the k/th smallest number in array

The SMALL function returns the k/th smallest number in array ignoring blanks.

SMALL(IF(COUNTIF($B$2:$B$21,$B$2:$B$21)>1,COUNTIF($A$2:$A$21,"<"&$A$2:$A$21),""),ROWS($A$1:A1))

becomes

SMALL({7;11; 8;19;"";17; "";"";""; 0;4;""; 14;"";"";13; 6;"";"";4},ROWS($A$1:A1))

becomes

SMALL({7;11; 8;19;"";17; "";"";""; 0;4;""; 14;"";"";13; 6;"";"";4},1)

and returns 0 (zero).

Step 4 - Identify position in cell range

The MATCH function returns the position of a value in a cell range or an array.

MATCH(SMALL(IF(COUNTIF($B$2:$B$21, $B$2:$B$21)>1, COUNTIF($A$2:$A$21, "<"&$A$2:$A$21), ""),ROWS($A$1:A1)), COUNTIF($A$2:$A$21, "<"&$A$2:$A$21), 0)

becomes

MATCH(0, COUNTIF($A$2:$A$21, "<"&$A$2:$A$21), 0)

becomes

MATCH(0, {7;11;8; 19;"";17;"";"";""; 0;4;"";14;""; "";13;6;""; "";4}, 0)

and returns 10.

Step 5 - Return value from cell range

INDEX($A$2:$A$21, MATCH(SMALL(IF(COUNTIF($B$2:$B$21, $B$2:$B$21)>1, COUNTIF($A$2:$A$21, "<"&$A$2:$A$21), ""),ROWS($A$1:A1)), COUNTIF($A$2:$A$21, "<"&$A$2:$A$21), 0))

becomes

INDEX($A$2:$A$21, 10)

and returns "1/10/2008" in cell D2.

Get Excel *.xlsx file

Filter duplicate values and sort by date.xlsx