## Compare two tables: Remove common records

**Table of Contents**

Let me demonstrate how to extract non common records from two tables. The formulas in this post contains the COUNTIFS function and is introduced in excel 2007.

The first example shows you how to hide common rows in a table. The second example describes how to compare two tables and extract not common rows/records using array formula.

### Example 1,

Sheet 1 and sheet 2 contains random data. As you can see, row 1 and 3 are common records between the two tables.

**Count records using COUNTIFS function**

- Select cell D2 in sheet1.
- Type
=COUNTIFS(Sheet2!$A$2:$A$4, A2, Sheet2!$B$2:$B$4, B2, Sheet2!$C$2:$C$4, C2)
in cell D2.

- Press Enter

The formula is instantly copied to all table cells in column D. The countifs function counts common records from two tables. Row 2 in sheet1 is found once in sheet 2 and so on.

**Hide common rows **

Common records are removed.

Repeat steps in **Count records using COUNTIFS function **and** Hide common rows **with sheet2.

### Example 2,

This example describes how to compare two tables and extract not common rows/records using an array formula.

Sheet1

Sheet2

Compare sheet

**Array formula in cell A2:**

This array formula may look complicated but it is not. It contains two different formulas. If the first formula returns an error, the second formula is calculated. The first formula extracts not common rows from the first table. The second formula extracts not common rows from the second table.

You can add a second IFERROR() function to the formula to remove #num errors.

### How to create an array formula

- Copy (Ctrl + c) and paste (Ctrl + v) array formula into formula bar.

- Press and hold Ctrl + Shift.
- Press Enter once.
- Release all keys.

### Explaining formula

This formula is the first formula. It extracts not common rows from the first table. The second formula is exactly the same but cell references are pointing to the second table.

**Step 1 - Identify common records**

COUNTIFS(criteria_range1,criteria1, criteria_range2, criteria2...)

Counts the number of cells specified by a given set of conditions or criteria

COUNTIFS(Sheet1!$A$2:$A$4, Sheet2!$A$2:$A$4, Sheet1!$B$2:$B$4, Sheet2!$B$2:$B$4, Sheet1!$C$2:$C$4, Sheet2!$C$2:$C$4)=0

becomes

COUNTIFS({"Martin";"Laura";"Margeret"}, {"Martin";"Ben";"Margeret"}, {"Anchorage";"New York";"London"}, {"Anchorage";"Los Angeles";"London"}, {26;28;25}, {26;28;25})=0

becomes

{1;0;1}=0 and returns {FALSE; TRUE; FALSE}

**Step 2 - Convert array into row numbers**

IF(COUNTIFS(Sheet1!$A$2:$A$4, Sheet2!$A$2:$A$4, Sheet1!$B$2:$B$4, Sheet2!$B$2:$B$4, Sheet1!$C$2:$C$4, Sheet2!$C$2:$C$4)=0, MATCH(ROW($A$2:$A$4), ROW($A$2:$A$4)), "")

becomes

IF({FALSE; TRUE; FALSE}, MATCH(ROW($A$2:$A$4), ROW($A$2:$A$4)), "")

becomes

IF({FALSE; TRUE; FALSE}, MATCH({2;3;4}, {2;3;4}), "")

becomes

IF({FALSE; TRUE; FALSE}, {1;2;3}), "")

and returns

{"";2;""}

**Step 3 - Return the k-th smallest number**

SMALL(array,k) returns the k-th smallest number in this data set.

SMALL(IF(COUNTIFS(Sheet1!$A$2:$A$4, Sheet2!$A$2:$A$4, Sheet1!$B$2:$B$4, Sheet2!$B$2:$B$4, Sheet1!$C$2:$C$4, Sheet2!$C$2:$C$4)=0, MATCH(ROW($A$2:$A$4), ROW($A$2:$A$4)), ""), ROW(A1))

becomes

SMALL({"";2;""}, ROW(A1))

becomes

SMALL({"";2;""}, 1)

and returns 2.

**Step 4 - Return a value of the cell at the intersection of a particular row and column**

INDEX(array,row_num,[column_num])

Returns a value or reference of the cell at the intersection of a particular row and column, in a given range

INDEX(Sheet1!$A$2:$C$4, SMALL(IF(COUNTIFS(Sheet1!$A$2:$A$4, Sheet2!$A$2:$A$4, Sheet1!$B$2:$B$4, Sheet2!$B$2:$B$4, Sheet1!$C$2:$C$4, Sheet2!$C$2:$C$4)=0, MATCH(ROW($A$2:$A$4), ROW($A$2:$A$4)), ""), ROW(A1)), COLUMN(A1))

becomes

INDEX(Sheet1!$A$2:$C$4, 2, COLUMN(A1))

becomes

INDEX(Sheet1!$A$2:$C$4, 2, 1)

becomes

INDEX({"Martin", "Anchorage",26;"Laura", "New York", 28;"Margeret", "London", 25}, 2, 1)

and returns "Laura" in cell A2.

### Download example file

remove common records.xlsx

Excel workbook 2007 *.xlsx

### Functions in this post:

**COUNTIFS(**criteria_range1,criteria1, criteria_range2, criteria2...**)**

Counts the number of cells specified by a given set of conditions or criteria

**MATCH(**lookup_value, lookup_array, [match_type]**)**

Returns the relative position of an item in an array that matches a specified value

**INDEX(**array,row_num,[column_num]**)**

Returns a value or reference of the cell at the intersection of a particular row and column, in a given range

**IF(**logical_test, [value_if_true], [value_if_false]**)
**Checks whether a condition is met, and returns one value if TRUE, and another value if FALSE

**SMALL(**array,k**)**

Returns the k-th smallest number in this data set.

## Compare two tables using a condition

There are two tables on this sheet. The array formula extracts common records in the two tables using a condition. There can be numerous occasions where this can be useful, for example comparing values on the same year or maybe year and month. The picture below shows common names in region Asia.

**Array formula in cell B14:**

**How to enter an array formula**

There are now curly brackets surrounding the formula in the formula bar.

### Defined tables

This example demonstrates how to filter not common values in region Asia using defined tables. I converted the two tables to excel defined tables.

**Formula in cell D3:**

=COUNTIFS(Table2[[Region ]],B3,Table2[Name],C3)>0

**Formula in cell H3:**

=COUNTIFS(Table1[Region],F3,Table1[Name],G3)>0

**Filter values**

- Click black arrow near header "Common"
- Deselect True
- Click Ok
- Click
- Click black arrow near header "Region"
- Deselect all values except "Asia"
- Click OK

### Download excel *.xlsx file

Extract shared values between two columns

Question: How can I compare two columns to find values that exists in both cell ranges? The picture above shows […]

Filter common values from three columns

Question: How do I filter values that exists in all three columns? Answer: Formula in A14: =INDEX(List1, MATCH(0, COUNTIF($A$13:A13, List1)+IF(IF(COUNTIF(List2, […]

Compare two tables: Filter common records

I will in this blog post describe how to extract common records from two data sets in Excel. I have […]

What values are missing in List 1 that exists i List 2?

Question: How to filter out data from List 1 that is missing in list 2? Answer: This formula is useful […]

Sean asks: How would you figure out an unique list where the sum of in one column doesn't match the […]

Filter values that exists in all three lists

Peter Voss asks: This is close to what I need. I have three lists of email addresses. If an email […]

Compare two columns and show differences

Array Formula in B11: =INDEX($B$3:$B$7, SMALL(IF(COUNTIF($D$3:$D$8, $B$3:$B$7)=0, MATCH(ROW($B$3:$B$7), ROW($B$3:$B$7)), ""), ROWS($A$1:A1))) To enter an array formula press and hold CTRL […]

Compare values between two columns and filter values existing in only one column

There are text values in column A and column B. The question is how do you compare the values in […]

How many common cell values are there in list 1 and 2?

Question: How many common cell values are there in list 1 and 2? Answer: Here is how to count matching […]

Compare two tables: Filter common records

I will in this blog post describe how to extract common records from two data sets in Excel. I have […]

Highlight records – multiple criteria [OR logic]

This blog post shows you how to highlight rows with multiple criteria using OR logic. The criteria is found in […]

Compare two lists of data: Highlight common records

Overview In this blog post you will learn how to: Create a countifs function Create a conditional formatting formula and […]

Compare two lists of data: Highlight records occurring in only one list

Overview There are two lists in this example: Sheet: List 1 Sheet: List 2 Create named ranges Select A2:A13 on […]

How to sort a table in a custom order in excel [No formula]

Your boss wants you to sort the company´s products by a new criterion, quality. You receive a list from your […]

This article describes how to highlight duplicate records and filter duplicate records. There is one record in each column, cell […]

Compare two lists of data: Filter records occurring in only one list

In this example we are going to use two lists with identical columns in excel 2007. It is easy to […]

This blog post shows you how to create a conditional formatting formula and highlight matching records. You can easily change […]

This blog post demonstrates how to quickly compare two tables in Excel. Table1 Table2 Create a fourth column and use […]

### 7 Responses to “Compare two tables: Remove common records”

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

Use the img tag, like this: <img src="Insert pic link here">

**Contact Oscar**

You can contact me through this contact form

This is really quality info. Thanks Oscar!!

Julián Fernández,

Thank you for commenting!

Really its super. Thank you !!

Example 1 was more helpful and easy way to identify common and uncommon records... This was really helpful. Thanks a lot !

krishna and Chamundeswari,

Thank you for commenting!

HI Oscar, I have almost similar data but in one sheet, seperate with some blank rows, i am trying to extract unique row by comparing both tables but not getting the answer.

Moreover, might possible both table wouldn't have same range, shall thi affect the formula...? TIA

Here is th formula I am trying..

=IFERROR(IFERR0R(INDEX($A$2:$B$7, SMALL(IF(COUNTIFS($A$2:$A$7, $A$11:$A$16, $B$2:$B$7, $B$11:$B$16)=0, MATCH(ROW($A$19:$A$26), ROW($A$19:$A$26)), ""), ROW(A18)), COLUMN(A18)), INDEX($A$11:$B$16, SMALL(IF(COUNTIFS($A$11:$A$16,$A$2:$A$7, $B$11:$B$16,$B$2:$B$7)=0, MATCH(ROW($A$19:$A$26),ROW($A$19:$A$26)), ""), ROW(A18)-SUM(--(COUNTIFS($A$2:$A$7,$A$11:$A$16, $B$2:$B$7,$B$11:$B$16)=0))), COLUMN(A18))), "")

KK,

The following article explains how to extract unique distinct records from two tables:

https://www.get-digital-help.com/2018/06/11/extract-unique-distinct-records-from-two-data-sets/