匹配和标记excel中重复的那些

时间:2017-06-29 12:27:08

标签: excel relational-database

我在Excel中有两个表

第一个表的产品清单带有ID

product_id   |  package_size   | package_name
1            |  40             | product 1
2            |  100            | product 2
2            |  100            | product 2
2            |  50             | product 2
3            |  100            | product 3
3            |  100            | product 3

第二个表有两列:

product_id   |  multiple_package_size
1            |  multiple_package_size
2            |  multiple_package_size
3            |  multiple_package_size

我希望在第二张桌子上返回的是:

product_id   |  multiple_package_size
1            | 
2            |           x
3            | 

现在我的multiple_package_size列为空,我试图在每个具有多个包大小的产品ID上放置一个x。我一直在使用INDEX MATCH,但它没有标记每个具有多个包大小的产品。 这是我现在在multiple_package_size列中的公式:

=if(INDEX(Sheet3!$E$1:$E$89999,MATCH(A29,Sheet3!$A$1:$A$89999,0)) = INDEX(Sheet3!$E$1:$E$89999,MATCH(A29,Sheet3!$A$1:$A$89999,1)),if(INDEX(Sheet3!$E$1:$E$89999,MATCH(A29,Sheet3!$A$1:$A$89999,1)) = INDEX(Sheet3!$E$1:$E$89999,MATCH(A29,Sheet3!$A$1:$A$89999,2)),if(INDEX(Sheet3!$E$1:$E$89999,MATCH(A29,Sheet3!$A$1:$A$89999,2)) = INDEX(Sheet3!$E$1:$E$89999,MATCH(A29,Sheet3!$A$1:$A$89999,3)),if(INDEX(Sheet3!$E$1:$E$89999,MATCH(A29,Sheet3!$A$1:$A$89999,3)) = INDEX(Sheet3!$E$1:$E$89999,MATCH(A29,Sheet3!$A$1:$A$89999,4)),if(INDEX(Sheet3!$E$1:$E$89999,MATCH(A29,Sheet3!$A$1:$A$89999,4)) = INDEX(Sheet3!$E$1:$E$89999,MATCH(A29,Sheet3!$A$1:$A$89999,5)),if(INDEX(Sheet3!$E$1:$E$89999,MATCH(A29,Sheet3!$A$1:$A$89999,5)) = INDEX(Sheet3!$E$1:$E$89999,MATCH(A29,Sheet3!$A$1:$A$89999,6)),if(INDEX(Sheet3!$E$1:$E$89999,MATCH(A29,Sheet3!$A$1:$A$89999,6)) = INDEX(Sheet3!$E$1:$E$89999,MATCH(A29,Sheet3!$A$1:$A$89999,7)),if(INDEX(Sheet3!$E$1:$E$89999,MATCH(A29,Sheet3!$A$1:$A$89999,7)) = INDEX(Sheet3!$E$1:$E$89999,MATCH(A29,Sheet3!$A$1:$A$89999,8)),if(INDEX(Sheet3!$E$1:$E$89999,MATCH(A29,Sheet3!$A$1:$A$89999,8)) = INDEX(Sheet3!$E$1:$E$89999,MATCH(A29,Sheet3!$A$1:$A$89999,9)),,"x"),"x"),"x"),"x"),"x"),"x"),"x"),"x"),"x")

易于阅读:

=if(INDEX(Sheet3!$E$1:$E$89999,MATCH(A29,Sheet3!$A$1:$A$89999,0)) = INDEX(Sheet3!$E$1:$E$89999,MATCH(A29,Sheet3!$A$1:$A$89999,1)),
if(INDEX(Sheet3!$E$1:$E$89999,MATCH(A29,Sheet3!$A$1:$A$89999,1)) = INDEX(Sheet3!$E$1:$E$89999,MATCH(A29,Sheet3!$A$1:$A$89999,2)),
if(INDEX(Sheet3!$E$1:$E$89999,MATCH(A29,Sheet3!$A$1:$A$89999,2)) = INDEX(Sheet3!$E$1:$E$89999,MATCH(A29,Sheet3!$A$1:$A$89999,3)),
if(INDEX(Sheet3!$E$1:$E$89999,MATCH(A29,Sheet3!$A$1:$A$89999,3)) = INDEX(Sheet3!$E$1:$E$89999,MATCH(A29,Sheet3!$A$1:$A$89999,4)),
if(INDEX(Sheet3!$E$1:$E$89999,MATCH(A29,Sheet3!$A$1:$A$89999,4)) = INDEX(Sheet3!$E$1:$E$89999,MATCH(A29,Sheet3!$A$1:$A$89999,5)),
if(INDEX(Sheet3!$E$1:$E$89999,MATCH(A29,Sheet3!$A$1:$A$89999,5)) = INDEX(Sheet3!$E$1:$E$89999,MATCH(A29,Sheet3!$A$1:$A$89999,6)),
if(INDEX(Sheet3!$E$1:$E$89999,MATCH(A29,Sheet3!$A$1:$A$89999,6)) = INDEX(Sheet3!$E$1:$E$89999,MATCH(A29,Sheet3!$A$1:$A$89999,7)),
if(INDEX(Sheet3!$E$1:$E$89999,MATCH(A29,Sheet3!$A$1:$A$89999,7)) = INDEX(Sheet3!$E$1:$E$89999,MATCH(A29,Sheet3!$A$1:$A$89999,8)),
if(INDEX(Sheet3!$E$1:$E$89999,MATCH(A29,Sheet3!$A$1:$A$89999,8)) = INDEX(Sheet3!$E$1:$E$89999,MATCH(A29,Sheet3!$A$1:$A$89999,9)),
,"x")
,"x")
,"x")
,"x")
,"x")
,"x")
,"x")
,"x")
,"x")

我做错了什么?有更好的方法吗?

1 个答案:

答案 0 :(得分:4)

您需要查看COUNTIF

=IF(COUNTIF(Sheet3!$A$1:$A$89999,A29) > 1, "x", "")
  

我做错了什么?

可能误解了MATCH函数的第三个参数。

如果第一个表格有重复的行,在第一个问题中看不到,那就更复杂了:

=IF(AGGREGATE(14,6,Sheet3!$I$1:$I$89999/(Sheet3!$A$1:$A$89999=A29),1)<>
    AGGREGATE(15,6,Sheet3!$I$1:$I$89999/(Sheet3!$A$1:$A$89999=A29),1),"x", "")

基本上它会比较匹配产品ID的最大和最小包装尺寸,如果它们不同,则会标记&#34; x&#34;。

P.S。我不完全确定列与您的数据完全对应我只是试图从您的公式猜测它们。我假设产品ID是sheet3列A,包大小是sheet3列I,搜索的值是A29。如果需要,可以调整它们。

p.s.2我认为你应该考虑从数据中删除重复项,如果这是一个选项。