## Create a unique distinct list based on criteria

The regular formula in cell E6 extracts unique distinct values from column B based on the corresponding number in column C, the min value is in cell F2 and the Max value is in cell F3.

Formula in cell E6:

### Explaining formula in cell E6

#### Step 1 - Prevent duplicate values

The COUNTIF function counts values based on a condition, in this case, multiple conditions. The first argument has an expanding cell range that grows when the cell is copied to cells below. This allows the formula to count for previously shown values.

COUNTIF($E$5:E5, $B$3:$B$12)=0

becomes

COUNTIF("Unique distinct list",{"AA";"DD";"EE";"BB";"AA";"AA";"BB";"CC";"CC";"BB"})=0

becomes

{0;0;0;0;0;0;0;0;0;0}=0

and returns

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

#### Step 2 - Check which records meet criteria

The less than and greater than signs lets you create logical expressions. Each condition is checked against the values in column C.

($C$3:$C$12<=$F$3)*($C$3:$C$12>=$F$2)

becomes

{7;9;9;8;2;6;3;2;1;8}<=8)*({7;9;9;8;2;6;3;2;1;8}>=2)

becomes

({TRUE;FALSE;FALSE;TRUE;TRUE;TRUE;TRUE;TRUE;TRUE;TRUE})*({TRUE;TRUE;TRUE;TRUE;TRUE;TRUE;TRUE;TRUE;FALSE;TRUE})

Both arguments must be TRUE, we must then multiply the arrays.

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

#### Step 3 - Multiply arrays

All criteria must be met.

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

becomes

{TRUE;TRUE;TRUE;TRUE;TRUE;TRUE;TRUE;TRUE;TRUE;TRUE}*{1;0;0;1;1;1;1;1;0;1}

and returns

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

#### Step 4 - Divide 1 with array

The LOOKUP function ignores errors, if we divide something with 0 (zero) we get #DIV/0! error.

1/((COUNTIF($E$5:E5,$B$3:$B$12)=0)*($C$3:$C$12<=$F$3)*($C$3:$C$12>=$F$2))

becomes

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

and returns

{1;#DIV/0!;#DIV/0!;1;1;1;1;1;#DIV/0!;1}.

#### Step 5 - Return value

LOOKUP(2, 1/((COUNTIF($E$5:E5, $B$3:$B$12)=0)*($C$3:$C$12<=$F$3)*($C$3:$C$12>=$F$2)), $B$3:$B$12)

becomes

LOOKUP(2, {1;#DIV/0!;#DIV/0!;1;1;1;1;1;#DIV/0!;1}, $B$3:$B$12)

becomes

LOOKUP(2, {1;#DIV/0!;#DIV/0!;1;1;1;1;1;#DIV/0!;1}, {"AA";"DD";"EE";"BB";"AA";"AA";"BB";"CC";"CC";"BB"})

### Get Excel *.xlsx file

unique-list-with-criteria_1v2.xlsx

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

### Excel categories

### 2 Responses to “Create a unique distinct list based on criteria”

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

I'm trying to create a unique distinct list from a column where an adjacent column has a specific name. I've looked at your guide where an adjacent column meets criteria, but this doesn't seem to help, I've simply replaced the

=INDEX(List_category, MATCH(0, COUNTIF($F$4:F4, List_category)+(List_value$E$2), 0))

With

=INDEX(List_category, MATCH(0, COUNTIF($F$4:F4, List_category)+(List_value="name"), 0))

where the name is actually a link to a cell with the name I'm looking for (format: $A$1)

This hasn't seemed to work for some reason, so I'm a bit stumped.

Could you offer any advice?

Thanks

Harry