How to compare two Excel sheets using VLOOKUP? [FREE Template]

Share

Facebook
Twitter
LinkedIn

You are the boss of ACME Inc. And one day, both of your accountants Sara and James come to you with two versions of the customer payment data. How do you compare these two Excel sheets and reconcile the data? We can use VLOOKUP to do just that. In this article, let me explain the step-by-step process.

Step 1: Set up data in two Excel sheets

Copy both sets of data to two sheets in an Excel file. For example, here I have two sheets – one with Sara’s data and another with James’ data. Both datasets have identical columns, but the data is not same.

Compare two Excel sheets with VLOOKUP

Step 2: Start with the first sheet and write the VLOOKUP formula

Go to the first sheet. Here, we are going to use VLOOKUP (or XLOOKUP, if you have Excel 365) to get the matching value from second sheet.

For the purpose of this exercise, you need a unique identifier column like Customer ID or invoice number.

In the adjacent column we are going to write the VLOOKUP function to get the corresponding values for the customer ID’s from second sheet. The set up should look like this:

Spreadsheet set up for comparing two sheets

Step 3: The LOOKUP formula

Write the VLOOKUP formula like this:

VLOOKUP Formula Explanation:

  • VLOOKUP formula finds matching value from a range. For example, here we can use it to search for the customer ID and get their payment details.
  • B3: refers to the cell with customer ID
  • ‘James Sheet’!$B$3:$C$32: is the range of data in second Excel sheet which we are trying to match
  • 2: is the column number of the “Amount paid” column in second sheet.
  • FALSE: ensures that VLOOKUP will look for an exact match in the second sheet.
  • Learn more about VLOOKUP function.

Or if you prefer to use XLOOKUP formula, use this:

VLOOKUP formula for comparing two sheets

Fill this formula down so you can see the matching values from second sheet.

At the end of this step, your first sheet should look like this:

If you have any missing IDs, those cells should have #N/A.

#N/A error in VLOOKUP when the ID is missing in the second worksheet

Step 4: Reconcile the values

Now that you have the matching value from second Excel sheet, let’s reconcile both to see which values matched and which values are different.

For this, we can use IF formula. Here is the formula:

Using IF formula to reconcile the results of two sheet comparison

This formula compares the first sheet value with the second sheet value and tells us if they are same or different. It also checks for the #N/A error and flags those records as “Missing ID”.

Fill the formula down and you will have reconciliation information for your data.

Completed reconciliation of the data

Now you can use FILTERS in Excel to see all matching or not matching records easily.

Step 5: Conditional format the non-matching records

Using conditional formatting to highlight unmatched values

This optional step helps us quickly spot all the non-matching and missing ID values quickly.

To do this,

  1. Select the entire range of data (for example: B3:E32)
  2. Go to Home ribbon > Conditional Formatting and click on “new rule”
  3. Select the rule type as “Use a formula to determine the…”
  4. Type the rule as =$E3 = “Not matching” (refer to the below image)
  5. Set the formatting to highlight the non-matching records
  6. Click OK to add the rule.
  7. Add one more rule for “ID missing” highlight and repeat steps 3 to 6
conditional formatting rule

When you finish, your data will highlight all the non-matching and missing ID values in different color so you can easily identify them.

Related: Learn more about Excel conditional formatting feature.

FREE Comparison & Reconciliation Template

If you need a quick template to compare two Excel sheets and reconcile the data, download my sample file here.

Other techniques to reconcile and compare two Excel sheets:

While using VLOOKUP is a quick and elegant way to compare two spreadsheets, Excel also offers few more options. These are:

  • Power Query: We can use Power Query to compare two sheets or two workbooks of data and reconcile the differences between values. Power Query also makes it easy to compare when you have multiple ID columns (for example: Customer ID & Date as the criteria for comparison). Refer to my Power Query tutorial page for more information on how to combine data with it.
  • Using XLOOKUP instead of VLOOKUP: As demoed above, we can use the new XLOOKUP function in Excel to perform the comparison. This allows for built-in error handling so we can see “Missing IDs” easily. Read more about XLOOKUP function here.
  • Using Conditional formatting: Excel’s conditional formatting also offers a powerful and simple way to compare two lists of values. See this page for details.
  • Using formulas vs. Power Query: I discuss the approaches for comparing two Excel sheets with formulas and PQ in my YouTube video here.
  • Using Pivot Tables: Excel Pivot tables can link two tables of data on a key column (like customer ID) so you can easily compare values from both in one view. This feature is called relationships. Learn more about Table Relationships in Excel here.

In conclusion…

Comparing two Excel sheets is an easy task once you know how to use the VLOOKUP (or XLOOKUP) function in Excel. I have used this exact approach countless times when dealing with multiple versions of files or different versions of truth. The process is easy, and the results are actionable.

Facebook
Twitter
LinkedIn

Share this tip with your colleagues

Excel and Power BI tips - Chandoo.org Newsletter

Get FREE Excel + Power BI Tips

Simple, fun and useful emails, once per week.

Learn & be awesome.

Welcome to Chandoo.org

Thank you so much for visiting. My aim is to make you awesome in Excel & Power BI. I do this by sharing videos, tips, examples and downloads on this website. There are more than 1,000 pages with all things Excel, Power BI, Dashboards & VBA here. Go ahead and spend few minutes to be AWESOME.

Read my storyFREE Excel tips book

Overall I learned a lot and I thought you did a great job of explaining how to do things. This will definitely elevate my reporting in the future.
Rebekah S
Reporting Analyst
Excel formula list - 100+ examples and howto guide for you

From simple to complex, there is a formula for every occasion. Check out the list now.

Calendars, invoices, trackers and much more. All free, fun and fantastic.

Advanced Pivot Table tricks

Power Query, Data model, DAX, Filters, Slicers, Conditional formats and beautiful charts. It's all here.

Still on fence about Power BI? In this getting started guide, learn what is Power BI, how to get it and how to create your first report from scratch.

21 Responses to “Distinct count in Excel pivot tables”

  1. Al says:

    The distinct count option works well but I have found that if I have a date field and want to group by year, month, etc. that option seems to be disabled. I need to do both, distinct count and group by year/month.
    Example data; sales orders with item quantities with dates.
    Challenge; sum the item quantities, count the distinct orders and group by month. How do I do this?
    Perhaps that's not possible due to the grouping?

    • Chandoo says:

      @Al... When you use data model based pivots, you cannot group values manually anymore. Why not use Excel 2016's default date grouping option? In this case we have just a few dates, so Excel is not grouping them, but if you have an year's worth of data, when you make the pivot with date in the row label area, Excel automatically groups them. If you have fewer dates or want to use your own grouping, just create a table with all dates, add columns with month, week, year etc. Then connect this table (these types of tables are usually called as calendar tables) to your data on date field as a relationship. Now you can create reports by month, quarter etc easily.

      • Dan says:

        Is this the only way to do it in 2013? I find it rather cumbersome to have to create another data table listing dates with the another column for MONTH() and YEAR() to be able to summarise data for senior level...

        • Chandoo says:

          I know people find adding calendar tables cumbersome, but it is a best practice and let's you add more layers of analysis quite easily. For example, adding analysis by weekday vs. weekend or by financial quarter or YTD calculations (you would need either Power Pivot DAX or some very carefully setup pivot table value field settings)

  2. NC says:

    I had absolutely no idea this was possible. Very useful, nice work!

  3. Pete says:

    Doesn't work for 2010 version though (or at least not my works version)

    • NARAYAN says:

      Hi ,

      The post has the following in it :

      These instructions work only in Excel 2016, Office 365 and Excel 2013.

  4. Sarah says:

    when i have 2 different Pivot tables, one without the enabled “Add this data to data model” option, and the other one with it enabled.. is there anyway i can link slicers between them?
    if the answer is NO,, what to do ?

  5. Edgar says:

    Quick note, the “Add this data to data model” option is not available for the Mac version.

  6. Steve Curtis says:

    perhaps outside scope of this article but I have found when I attempt to create a pivot table from an external data source (connection to a sql view) the "Add this data to data model" becomes greyed out. Anybody experienced and found a solution so I can start getting distinct count in my pivot tables?

  7. Kelly Nanfito says:

    Is there a way to still add a calculated field when using distinct count?

  8. Luna says:

    I found I can't change the date source after tick the " add this data to the data model", can you help to adv how to change the date source in such case?

  9. Chris says:

    Is there a way to update the source once you have added to the data model? I receive a new spreadsheet weekly and would like to update the connection so my tables pull from the new source.

  10. Ankit Moral says:

    A big Thank you. It worked.

  11. Mohapi says:

    Hi, have survey data that I need to analyze but the challenge is that my key fields are showing horizontally. I tried to transpose the fields using Power Query, but unfortunately the new fields are returning same values on a pivot table despite using distinct values

  12. sorina says:

    How I can a do a pivot table with discount conts in some columns and then generate shor report filter pages. pls it drives crazy

  13. ira says:

    Hi. Why grand total pivot of distinct count is 13? shouldn't it be 67?

  14. Asia says:

    Great Answer! Saved me lots of time!
    Thank you!!!

  15. Suresh says:

    Worked awesome! Thanks!!

  16. Mayank says:

    Hi Chandoo,
    I am using pivot tables for distinct count and now I need to update them with new set of data. But when I update the source data, all the columns and formatting of Pivot table disappears and I need to build it from Scratch.

    Is there a possibility that I can update the source data with new rows added and also retain my pivot tables?

Leave a Reply