简体   繁体   中英

EXCEL: How to merge 2 sets of customer data

I am sure this question has a really easy answer, but after extensive research I have somehow not found what I was looking for. I am not an excel pro, but do have some experience with it.

Basically I have 2 sets of data that is indexed by customer account number and gives certain values, such as sales, profits, costs etc in the one file and sales rep responsible, amount of times contacted in the other file.

My goal now is to get these two files into one, so that I have the customer ID in the first column and all the data respective to that customer number in the columns next to it on one sheet.

However the customer numbers from the two sheets are not sorted in any way so I cant just copy and paste it and i am dealing with quite a large data set so I cannot just do it manually. additionally there are more customers id's in the first sheet than in the second, since some data is missing for a certain amount of the customers.

How can I basically automatically merge the data belonging to each customer so that it ends up being displayed in one row?

I recommend that you approach the merging of these two lists by creating a 3rd, comprehensive listing, which pulls from your raw data files.

Setting up your new Results Sheet

Assume that one list is in Book1, sheet1, and the other list is in Book2, sheet1. Open up a new excel file. Put the headers along the top. Next, you will create an index which shows all unique customer ID numbers, sorted by number. This will only work if there are no duplicate ID's (except for the ones which refer to the same cusotmer).

Copy the Customer ID column manually from Book1 into the New book. Copy the customer ID's from Book2 manually, underneath the Book1 customers, in the same column in the New book. Highlight the customer ID column. Go to the Data ribbon, then Remove Duplicates. Then rightclick your data and click 'sort'. This will leave you with an ordered customer ID column, and all other fields under the other headings will be blank.

Vlookup Formula

Next, you will use 2 vlookup formulas, similar to what @StaceyBurns recommends below. Vlookup takes a specific unique value, and looks for that value on the leftmost column of a datablock. Then it finds the first time there's a match for that value, and returns a value from a cell on that row, a given number of columns away. So for example:

=VLOOKUP(A1,B1:D5,2,FALSE)

Says: Take the unique value found in A1, look for that value in column B, from row 1:5, and return the 2nd column's result out of the datablock B:D (column C). So if A1 was the same as B3, this formula would provide the result for C3. FALSE means it would try and approximate your value if there's no match.

Assume customer indexes for all files are in column A. Assume also that all other headers are in the same order, let's say from A1:H1. Your formula to use VLOOKUP in the new workbook would be as follows - put this in B2:

=VLOOKUP($A2,[Book1.xlsx]Sheet1!$A:$H,column(),FALSE)

This gives you the matching amount under Sheet1's column B header, where Sheet1!'s customer ID matches the customer ID shown in cell A2 of the New book. However, we need to know whether it was able to properly pick up a value from Book1 - because we know that some data is incomplete. So, let's check if the above result is either a number, or text:

Determining if Results are found in Sheet1

=OR(ISTEXT(VLOOKUP($A2,[Book1.xlsx]Sheet1!$A:$H,COLUMN(),FALSE)),ISNUM(VLOOKUP($A2,[Book1.xlsx]Sheet1!$A:$H,COLUMN(),FALSE)))

This will return TRUE if the result is either a Number, or Text. So it will return FALSE if either no match is found for that ID number on Book1 Sheet1, or if the result is a blank cell. So now we put that inside of an IF statement - if it returns true, we want the result from Book1. If it returns false, we want to attempt to pull the result from Book2, through the exact same formula. This whole thing will look like this:

Final Formula

=IF(OR(ISTEXT(VLOOKUP($A2,[Book1.xlsx]Sheet1!$A:$H,COLUMN(),FALSE)),ISNUM(VLOOKUP($A2,[Book1.xlsx]Sheet1!$A:$H,COLUMN(),FALSE))),VLOOKUP($A2,[Book1.xlsx]Sheet1!$A:$H,COLUMN(),FALSE),VLOOKUP($A2,[Book2.xlsx]Sheet1!$A:$H,COLUMN(),FALSE))

Now, it will try to find the match from Book1 - if there's no match for the ID, or if the match returns a blank value for that header, then it will try to find a match from Book2. If it finds no match there, it will return #N/A! (which shouldn't happen, because that means you've deleted one of the customer ID's that we pulled directly from Book1 & Book2). It might return a blank cell if that data piece is not in either sheet. This formula can be copied from B2 all the way to the bottom right of your data block in your results sheet.

You can use the VLOOKUP function on the first sheet to bring the data from the second sheet in.

So for example, take an empty column on your first sheet and add the VLOOKUP function which looks like this:

=VLOOKUP(cell to lookup,
set of data on 2nd file,
column index on 2nd file of data you want,
TRUE/FALSE Boolean to ask for either close match or exact match )

If your Customer ID is in column A and your second sheet looks like this:

A1 Customer ID

B2 Sales Rep

C3 Number of Times Contacted

then you would do a look up first for the Sales Rep:

=VLOOKUP(A1,Sheet2!$A$1:$C$15,2,FALSE)

Then double click on the bottom right corner of this cell to populate the formula for all your rows.

Then do the same in a new cell for the Number of Times Contacted:

=VLOOKUP(A1,Sheet2!$A$1:$C$15,3,FALSE)

(Note I used C15 as an example in the above VLOOKUP . It should be the number of rows you have on file 2)

More info: https://support.office.com/en-us/article/VLOOKUP-function-0bbc8083-26fe-4963-8ab8-93a18ad188a1

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM