HomeGoogle DocsSpreadsheetGoogle Sheets: Compare Two Lists and Extract the Differences

Google Sheets: Compare Two Lists and Extract the Differences

Published on

To compare two lists and extract the differences you can use the COUNTIF and IF function combination in Google Sheets. It’s two dimensional.

For example, I have taken quotations from two vendors for plumbing materials. Both of the vendors provided their quotation based on the availability of materials with them. Now I can compare these two lists in different ways.

  1. Compare the list provided by vendor 1 with my original requirement and find the nonavailable items.
  2. I can also find the items in the provided list of vendor 1, that do not match my requirements.

This test is also required as sometimes the vendor may offer alternate items in his list.

I hope the following comparison can give you more insight regarding this.

compare 2 lists and extract the differences in Google Sheets

My requirements are in Column A and what the vendor 1 offered (quoted) is in Column B.

Since it’s a small list, you can manually find the items that are not in the offered list. With the help of my custom Google Sheets formula, I’ve found that in Column C.

In Column D, I have listed the additional items that the vendor offered, which are not in my original requirement in Column A.

In Google Sheets, you can easily compare two lists and extract the differences. Here is that formula.

The Formula to Compare Two Lists and Extract the Differences in Google Sheets

The Formula in C2:

Compare column A with column B and return the items in column A that is not in column B.

Formula:

=ArrayFormula(sort(if(COUNTIF(B2:B,A2:A)=0,A2:A,)))

In this case, you should use the Column A values as the conditions in Countif. That’s important.

This formula follows the below COUNTIF syntax.

COUNTIF(range, criterion)

The COUNTIF formula returns a conditional (A2:A contains the conditions) count across a range (B2:B is the range).

This conditional count formula returns the value 1 or more for matches and 0 for differences.

We can use the IF function to return the items in column A wherever the count is 0.

Reference: Google Sheets Function Guide by Info Inspired

The Formula in D2:

Compare column B with column A and return the items in column B that is not in column A.

Here, we should use the Column B value as the Countif condition.

=sort(if(COUNTIF(A2:A,B2:B)=0,B2:B,))

This way you can compare two lists and extract the differences in Google Sheets.

Question:

I have a list of names in Column Y and another list in Column Z. I want to find the names in Column Y that are not in Column Z. In this case, which columns should I use as the Countif Rage and Condition?

Answer:

No doubt the conditions should be the column Y range in the Countif. Then obviously the data range would be the Column Z range.

Before winding up this tutorial I am sharing one more formula with you.

Want to find the matches in two lists?

=sort(if(COUNTIF(B2:B,A2:A)=1,A2:A,))

This formula compares the list 1 with list 2 (Colum A with Column B) and extracts the common items.

Similar Google Sheets Formula Examples:

  1. How to Compare Two Columns for Matching Values in Google Sheets.
  2. The Formula to Find Partial Match in Two Columns in Google Sheets.
Prashanth KV
Prashanth KV
Your Trusted Google Sheets and Excel Guide Prashanth KV brings a wealth of experience in Google Sheets and Excel, cultivated through years of work with multinational corporations in Mumbai and Dubai. As a recognized Google Product Expert in Docs Editors, Prashanth shares his expertise through insightful blogging since 2012. Explore his blog for practical tips and guidance on maximizing your spreadsheet skills.

SORT and SORTBY – Excel Vs Google Sheets

While Excel offers the SORT and SORTBY functions for sorting a table, Google Sheets...

Get Top N Values Using Excel’s FILTER Function

When using the FILTER function in Excel to extract the top N values, it's...

XLOOKUP in Excel: Working with Visible Rows in a Table

In Excel, the XLOOKUP function isn't inherently designed to exclusively work with visible rows;...

SUMPRODUCT Differences: Excel vs. Google Sheets

The core purpose of the SUMPRODUCT function remains consistent across both Excel and Google...

More like this

Interactive Random Task Assigner in Google Sheets

You have multiple tasks and multiple people. Here's a fun way to randomly assign...

Google Sheets Bar and Column Chart with Target Coloring

To color each data point in the column or bar chart according to the...

Analyzing Column A Between Non-Adjacent Values in Column B: Google Sheets

This tutorial addresses a common scenario encountered in Google Sheets: how to sum, average,...

6 COMMENTS

  1. Hey, Thank you.
    What if the item repeats?
    Say, for example, Item 6 is twice in column A and only once in column B.

  2. Great article, helped me a lot!

    But although I could do what I intended in my project, I still don’t understand one thing. Could you explain this or direct me to some reading that does?

    In the formula: =sort(if(COUNTIF(A2:A,B2:B)=0,B2:B,))

    The IF returns blank if there is a difference and it is false, doesn’t it?

    Then the SORT returns the list of values that are different. I don’t understand how the SORT function gets these values or what the IF is actually returning as value_if_false.

    • Hi, gustavo,

      To understand the logic, please make a table as per my example (cell range A1:B7).

      Then in cell H2, insert the below Countif.

      =ArrayFormula(COUNTIF(A2:A10,B2:B10))

      Note:- You won’t see ArrayFormula use in my original formula. I’ll come to that below.

      You can see that it returns the numbers 1 and 0 (against B2:B10). The number 1 for the match and 0 for the mismatch.

      The logical_expression in IF is ArrayFormula(COUNTIF(A2:A10,B2:B10))=0

      value_if_true – return values from B2:B10
      value_if_flase – return blank

      The SORT plays two roles.
      1. It’s an alternative to the above ArrayFormula use. So COUNTIF works without any issue in a cell range.
      2. The second one is most important. Without SORT, you may have blanks between the values in the IF result. By sorting, we can solve it.

  3. This is a great help, thanks for the info. Could you help with how to get the count of the number of items in column A which are not present in Column B?

LEAVE A REPLY

Please enter your comment!
Please enter your name here

This site uses Akismet to reduce spam. Learn how your comment data is processed.