# Working with unique values

### What's on this page

## 1. Extract unique values from two columns - Excel 365

The image above demonstrates an Excel 365 formula in cell F3 that extracts unique values from two different columns. The columns are not adjacent and are not equal in size.

The first cell range B3:B6 contains "AA", "BB", "AA", and "CC". The second cell range D3:D7 contains "CC", "DD", "CC", and "EE". Unique values are "BB" and "EE" if you take both cell ranges into account.

Excel 365 dynamic array formula in cell F3:

This formula works only in Excel 365 and is entered as a regular formula despite its name. It spills values to cells below as far as needed.

The formula returns a #SPILL error if one or more cells are populated with characters. Delete the values and the formula spills values to cells below automatically.

### Explaining formula in cell F3

#### Step 1 - Stack cell ranges vertically

The VSTACK function combines cell ranges or arrays. Joins data to the first blank cell at the bottom of a cell range or array (vertical stacking)

Function syntax: VSTACK(array1,[array2],...)

VSTACK(B3:B6, D3:D7)

becomes

VSTACK({"AA"; "BB"; "AA"; "CC"}, {"CC"; "DD"; "DD"; "CC"; "EE"})

and returns

{"AA"; "BB"; "AA"; "CC"; "CC"; "DD"; "DD"; "CC"; "EE"}

#### Step 2 - Extract unique values

The UNIQUE function returns a unique or unique distinct list.

Function syntax: UNIQUE(array,[by_col],[exactly_once])

UNIQUE(VSTACK(B3:B6, D3:D7),,1)

becomes

UNIQUE({"AA"; "BB"; "AA"; "CC"; "CC"; "DD"; "DD"; "CC"; "EE"},,1)

and returns

{"BB"; "EE"}.

## 2. Extract unique values from two columns - earlier Excel versions

I read an article Merging Lists To A List Of Distinct Values at CPearson. The article describes code that you can use to merge two lists into a third list and prevent duplicate entries in the resulting list, using VBA to create a macro.

Here is a solution to create a unique list from two columns without using VBA.

The picture below shows the unique list in columnÂ F.

The following formula returns values that are unique from two columns combined. Unique values are values that only exist once in both columns.

Formula in cell F3:

### Explaining formula in cell F3

This formula may seem big, however, it is actually two smaller formulas combined. If you want to see the calculation steps then go to tab "Formulas" on the ribbon and press with left mouse button on "Evaluate Formula" button, then press with left mouse button on "Evaluate" button to move to next step in the calculation.

#### Step 1 - Prevent duplicate values

The COUNTIF function is really helpful in this situation, it counts the values in order to display unique values from two columns combined.

COUNTIF(F2:$F$2, $B$3:$B$6)

becomes

COUNTIF("Unique list", {"AA";"BB";"AA";"CC"})

and returnsÂ {0;0;0;0}.

#### Step - 2 - Count values in List1 against List 2

COUNTIF($D$3:$D$7, $B$3:$B$6)

becomes

COUNTIF({"CC";"DD";"DD";"CC";"EE"}, {"AA";"BB";"AA";"CC"})

and returns {0;0;0;2}. This tells us that only "CC" has a duplicate in List2.

#### Step 3 - Count values in List1

The following COUNTIF formula identifies unique values in cell rangeÂ $B$3:$B$6

COUNTIF($B$3:$B$6, $B$3:$B$6)

becomes

COUNTIF({"AA";"BB";"AA";"CC"}, {"AA";"BB";"AA";"CC"})

and returns

{2;1;2;1}.

#### Step 4 - Add arrays

(COUNTIF(F2:$F$2, $B$3:$B$6)+COUNTIF($D$3:$D$7, $B$3:$B$6)+COUNTIF($B$3:$B$6, $B$3:$B$6))

becomes

{0;0;0;0} +Â {0;0;0;2} +Â {2;1;2;1}

equals

{2;1;2;3}.

#### Step 5 - Check if value in array is equal to 1

(COUNTIF(F2:$F$2, $B$3:$B$6)+COUNTIF($D$3:$D$7, $B$3:$B$6)+COUNTIF($B$3:$B$6, $B$3:$B$6))=1

becomes

{2;1;2;3}=1

and returns

{FALSE;TRUE;FALSE;FALSE}.

#### Step 6 - Divide 1 with array

1/((COUNTIF(F2:$F$2, $B$3:$B$6)+COUNTIF($D$3:$D$7, $B$3:$B$6)+COUNTIF($B$3:$B$6, $B$3:$B$6))=1)

becomes

1/({FALSE;TRUE;FALSE;FALSE})

and returns

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

#### Step 7 - Return value based on array

LOOKUP(2, 1/((COUNTIF(F2:$F$2, $B$3:$B$6)+COUNTIF($D$3:$D$7, $B$3:$B$6)+COUNTIF($B$3:$B$6, $B$3:$B$6))=1),$B$3:$B$6)

becomes

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

becomes

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

and returns "BB" in cell F3.

#### Step 8 - Return values from List 2

When the first formula returns errors the IFERROR function directs to the next formula. The next formula is exactly the same as the first formula except that it gets values from List 2.

=IFERROR(formula1, formula2)

### Get excel sample file for this tutorial

unique list from two columnsv2.xlsx

## 3. Filter unique values and sort based on adjacent date - Excel 365

This example shows an Excel 365 formula in cell E3 that creates a list of unique values based on cell range C3:C22 and sorts the values by the corresponding dates in B3:B22 from small to large.

Unique values are values that exist only once in C3:C22. Excel dates are integers formatted as dates, this makes it possible to add and subtract dates easily, it also makes it possible to sort dates.

Excel 365 dynamic array formula in cell E3:

This formula works only in Excel 365 and is entered as a regular formula despite its name. It spills values to cells below as far as needed.

The formula returns a #SPILL error if one or more cells are populated with characters. Delete the values and the formula spills values to cells below automatically.

### Explaining formula in cell E3

#### Step 1 - Find unique values

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

Function syntax: COUNTIF(range, criteria)

COUNTIF(C3:C22,C3:C22)=1

becomes

{2;2;3;2;1;2;1;1;1;3;2;1;2;1;1;3;2;1;1;2}=1

The equal sign lets you compare value to value, it returns a boolean value TRUE or FALSE.

{2;2;3;2;1;2;1;1;1;3;2;1;2;1;1;3;2;1;1;2}=1

returns

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

#### Step 2 - Filter unique values and corresponding date

The FILTER function extracts values/rows based on a condition or criteria.

Function syntax: FILTER(array, include, [if_empty])

FILTER(B3:C22,COUNTIF(C3:C22,C3:C22)=1)

becomes

FILTER(B3:C22,{FALSE; FALSE; FALSE; FALSE; TRUE; FALSE; TRUE; TRUE; TRUE; FALSE; FALSE; TRUE; FALSE; TRUE; TRUE; FALSE; FALSE; TRUE; TRUE; FALSE})

and returns

{39760,"DD"; 39748,"YY"; 39649,"UU"; 39638,"LL"; 39789,"CC"; 39509,"MM"; 39471,"EE"; 39509,"TT"; 39683,"II"}

#### Step 3 - Sort array based on first column from small to large

The SORT function sorts values from a cell range or array

Function syntax: SORT(array,[sort_index],[sort_order],[by_col])

SORT(FILTER(B3:C22,COUNTIF(C3:C22,C3:C22)=1))

becomes

SORT({39760,"DD"; 39748,"YY"; 39649,"UU"; 39638,"LL"; 39789,"CC"; 39509,"MM"; 39471,"EE"; 39509,"TT"; 39683,"II"})

and returns

{39471,"EE";39509,"MM"; 39509,"TT"; 39638,"LL"; 39649,"UU"; 39683,"II"; 39748,"YY"; 39760,"DD"; 39789,"CC"}

### Get Excel *.xlsx file

Filter unique values and sort by date.xlsx

### Unique values category

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

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

Table of Contents How to find the largest duplicate number How to find the largest duplicate number - Excel 365 […]

### Excel categories

### 25 Responses to “Working with unique values”

### 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've been searching for articles to help me to identify unique data across multiple Excel columns, and yours is the closest I have found. However, it seems to deal with only two (2) columns at a time. Is it expandable to cover more than two, in particular where the columns are not adjacent?

What I have is a grid of results:

Cols A, B, C reference result set 1 (with the potentially duplicate data in Col C)

Cols D, E, F reference result set 2 (with the potentially duplicate data in Col F)

and so on, with potentially result sets. The pracical number of rows involved is likely to be no more than 500.

What I need to do is to count all the unique entries in Col C, Col D, Col as a combined set, such that if Col C has data "abc", and Col also has the same data, then the data is only counted once. (I don't actually need to generate a new list of the unique data, but if that is a required stage in the calculation it is not a problem.) Note that can be any value, but is likely to not exceed 500 columns.

Could you advise me if there is a specific, formulaic (not VBA) solution to the problem? If so, could you provide a clue to solving it?

Many Thanks,

Nigel Edwards.

Thanks for commenting!

Interesting question, I have to think about this question for a while...

I created an array formula that counts unique distinct values in three different ranges.

https://www.get-digital-help.com/count-unique-distinct-values-in-three-columns-combined-in-excel/

Hi Oscar,

Would be possible to share this formula again.

It looks like link is years old and was probably disabled.

Much appreciate.

hi, i'm curious on this solution.

Is there a simpler/shorter formula to extract non-duplicate entries?

output shall be BB and EE (non-duplicates on both columns).

I have updated this blog post. I think the formula is somewhat shorter and uses less named ranges.

xcellent!!! thanks!!

Hi,

Just found the site and wow! I've already fixed a few sloppy problems in some my work spreadsheets.

Sorry in advance if this is the wrong way to ask a question.

But this page is the closet I've found to what I am trying to do. I have a table with four columns, Date, Name, Level, and outcome. The range is from row 3 to row 1000.

What I need to be able to do is look at today's date. Determine the month and year and then look up all the values in the date column that match the month and year. I've been trying to get it to work with sumproduct but I can't wrap my head around it.

Then on a separate tab list all the unique events for that month.

So one the seperate tab it would show something like this:

May 2/2010 Bob Smith 3 Requires Attention

May 5/2010 Jim Smith 1 Out of Service

Hope you are able to help. Thanks in advance.

Dave,

see this post: https://www.get-digital-help.com/2010/05/05/list-all-the-unique-events-for-a-month-in-excel-array-formula/

Thanks! Works like a treat

I tried this and it gives a divide by zero error. The reason is countif() gives a 0. What are you trying to do with the countif, seems like that using 2 ranges are arguments is not allowed.

Scott,

I think you might have blanks in your two lists?

Get the Excel file

Scott.xls

I am trying to filter dates (with days) using month and year as follows:

=SUMIFS('DATA INPUT'!$C$3:$C$5000,TEXT('DATA INPUT'!$B$3:$B$5000, "yyyy-mmm"),TEXT(E$1,"yyyy-mmm"),'DATA INPUT'!$D$3:$D$5000,"Pilsner",'DATA INPUT'!$E$3:$E$5000,"Beer pack")

- Column "C" is what I would like to sum

- Column "B" is the dates I am TRYING to filter using E1 (inputted month)

- Column "D" and "E" are standard text to be filtered

I have tried playing with the concepts above but to no avail, any ideas? I would like to avoid VBA, etc.

Chris,

Array formula in F1:

Your formula:

becomes

Entered as an array formula.

I may be a bimbo, but I can't figure this out. I have five rows that need to change, sorted by date from the first row.

here are my row names: due date, author, title, changes, date completed

I want the due dates to all be in order, changing the corresponding columns.

HELP a homegirl out! PLEASE!

oh and i have a MAC.

amber,

Is this what you had in mind?

Sort from left to right

Hi

I've gotten this to partially work. The problem is my data is split over 4+ columns. So Column A would be Columns S,AA,AI,etc and column B is Columns O,W,AE,etc.

This works:

Date (S2:S21)

Values (O2:O21)

But when I try to add other columns to the named ranges it doesn't like it. This doesn't work:

Data (S3:S42,AA3:AA24)

Values (O3:O42,W3:W24)

Thanks

Laura,

you are right, it does not work. I donÂ´t have a solution for you.

Suppose if i want the unique list to be start from F3 means, then i have to change C9:$C$9 to F2:$F$2....but i want the list to be start from F1 then what should i write in the formula...instead of C9:$C$9 can i write F0:$F$0. Note: I dont want any heading. I want the list to be start from F1.Please provide the solution

Shariff,

Suppose if i want the unique list to be start from F3 means, then i have to change C9:$C$9 to F2:$F$2...Yes, correct!

but i want the list to be start from F1 then what should i write in the formula...instead of C9:$C$9 can i write F0:$F$0. Note: I dont want any heading. I want the list to be start from F1.Please provide the solution

Great question and I donÂ´t know the answer. I donÂ´t think you can.

How to just list out the unique from list 1

Nguyen Hai Tuan

Read this:

https://www.get-digital-help.com/how-to-extract-a-unique-list-and-the-duplicates-in-excel-from-one-column/

Dear Sir,

I handle bankruptcy cases for many companies. The details of each company are maintained in different workbooks. The reporting compliances and the processes have very stringent timelines. I need to have all the details of reporting requirements and processes due yesterday to three days from now on a single master sheet distinct from these workbooks.

The details of the reporting required and processes are on the columns G, I K, M O, R of worksheet "REPORTING" and column h of "PROCESS".

PLEASE help me with a formula or a vba code by which I can get the complete rows where the relevant dates appear on the master sheet mentioned above.

I have tried working with the formulas given by you, as I find your solutions to be effective as you explain them nicely and the logic once clearly understood, can be applied anywhere.

I have been able to get the answer for a column but not the complete row, if I am using the same worksheet or even the same workbook but not on a separate workbook. Besides, I get a #num wherever the dates are out of range. Is it possible to get a blank instead of this error message.

I have been struggling with this for long. Kindly help. I have attched the link to my google drive in the column for website. Just for information I use macbook pro and ms excel for mac.

A big thank you for bringing me upto this point ans bigger thank you in advance for leading me to the destination.

Can this formula be changed to an array formula? I also need the DISTINCT values (not UNIQUE values) from both the columns. for e.g. A,B,C from List 1 and C,D,E from List 2, which when combined should result in A,B,C,D,E.