简体   繁体   English

EXCEL:如何合并2套客户数据

[英]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. 我不是excel专业人士,但确实有一些经验。

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. 我现在的目标是将这两个文件合而为一,以便我在第一列中具有客户ID,并在一张纸上的第二列中具有与该客户号有关的所有数据。

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. 此外,第一张工作表中的客户ID比第二张工作表中的要多,因为某些数量的客户缺少某些数据。

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. 假定一个列表在Book1的sheet1中,而另一个列表在Book2的sheet1中。 Open up a new excel file. 打开一个新的Excel文件。 Put the headers along the top. 将标题放在顶部。 Next, you will create an index which shows all unique customer ID numbers, sorted by number. 接下来,您将创建一个索引,该索引显示所有唯一的客户ID号,并按编号排序。 This will only work if there are no duplicate ID's (except for the ones which refer to the same cusotmer). 仅当没有重复的ID时才有效 (除了引用相同cusotmer的ID除外)。

Copy the Customer ID column manually from Book1 into the New book. 手动将“客户ID”列从Book1复制到“新书”中。 Copy the customer ID's from Book2 manually, underneath the Book1 customers, in the same column in the New book. 在“新书”的同一列中,从Book1客户下面的Book2中手动复制客户ID。 Highlight the customer ID column. 突出显示客户ID列。 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. 这将为您留下一个订购的客户ID列,而其他标题下的所有其他字段将为空白。

Vlookup Formula Vlookup公式

Next, you will use 2 vlookup formulas, similar to what @StaceyBurns recommends below. 接下来,您将使用2个vlookup公式,类似于@StaceyBurns在下面建议的公式。 Vlookup takes a specific unique value, and looks for that value on the leftmost column of a datablock. Vlookup采用一个特定的唯一值,并在数据块的最左列上查找该值。 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). 说:取在A1中找到的唯一值,从行1:5在B列中查找该值,然后从数据块B:D(列C)中返回第二列的结果。 So if A1 was the same as B3, this formula would provide the result for C3. 因此,如果A1与B3相同,则此公式将为C3提供结果。 FALSE means it would try and approximate your value if there's no match. FALSE表示如果没有匹配项,它将尝试估算您的值。

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. 假设所有文件的客户索引都在A列中。还假设所有其他标头的顺序相同,例如从A1:H1开始。 Your formula to use VLOOKUP in the new workbook would be as follows - put this in B2: 在新工作簿中使用VLOOKUP的公式如下-将其放在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. 这会在Sheet1的B列标题下为您提供匹配的金额,其中Sheet1!的客户ID与新书的单元格A2中显示的客户ID匹配。 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. 但是,我们需要知道它是否能够从Book1中正确获取值-因为我们知道某些数据是不完整的。 So, let's check if the above result is either a number, or text: 因此,让我们检查以上结果是数字还是文本:

Determining if Results are found in Sheet1 确定是否在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. 如果结果是数字或文本,则将返回TRUE。 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. 因此,如果在Book1 Sheet1上找不到该ID号的匹配项,或者结果为空白单元格,它将返回FALSE。 So now we put that inside of an IF statement - if it returns true, we want the result from Book1. 因此,现在将其放入IF语句中-如果它返回true,则需要Book1的结果。 If it returns false, we want to attempt to pull the result from Book2, through the exact same formula. 如果返回false,则我们希望通过完全相同的公式从Book2中提取结果。 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. 现在,它将尝试从Book1中找到匹配项-如果ID不匹配,或者该匹配项返回该标头的空白值,则它将尝试从Book2中找到匹配项。 If it finds no match there, it will return #N/A! 如果没有找到匹配项,它将返回#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). (这不应该发生,因为这意味着您已经删除了我们直接从Book1和Book2中提取的客户ID之一)。 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. 该公式可以从B2一直复制到结果表中数据块的右下角。

You can use the VLOOKUP function on the first sheet to bring the data from the second sheet in. 您可以在第一张纸上使用VLOOKUP函数将第二张纸中的数据引入。

So for example, take an empty column on your first sheet and add the VLOOKUP function which looks like this: 因此,例如,在第一张工作表上留空列,并添加如下所示的VLOOKUP函数:

=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: 如果您的客户ID在A列中,并且您的第二张纸像这样:

A1 Customer ID A1客户编号

B2 Sales Rep B2销售代表

C3 Number of Times Contacted C3联系次数

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) (请注意,我在上面的VLOOKUP中以C15为例。它应该是文件2中的行数)

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

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

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