[英]Excel: If function that filters a table by two columns and sees if a third column has more than one unique value
I am trying to identify if a customer (customer A) purchased both Apples and Bananas on the same day based on a table of data. 我试图确定客户(客户A)是否在同一天根据数据表购买了苹果和香蕉。 Column A identifies the Customer, Column B the day that the customer made a purchase, and Column C the fruit that they purchased. A列表示客户,B列表示客户购买的日期,C列表示他们购买的水果。 I simply want an IF statement that indicates whether, if on any day, the specified customer purchased both Apples and Bananas. 我只想要一个IF声明,表明在任何一天,指定的客户是否同时购买了苹果和香蕉。 In other words, for a specified customer, I want an output cell to indicate if "Yes", there is a day on which the specified customer purchased apples and bananas, or "No" there wasn't. 换句话说,对于指定的客户,我想要一个输出单元格来指示“是”,指定的客户是否购买了苹果和香蕉,或者“否”没有。
Customer Date Fruit Purchased
A 2016/09/08 Apples
B 2016/09/09 Apples
C 2016/08/10 Apples
A 2016/09/08 Bananas
B 2016/08/12 Bananas
C 2016/09/13 Bananas
A 2016/09/13 Apples
Given the above table, if I specify Customer A as my customer, the formula should indicate "Yes", as customer A purchased Apples and Bananas on 2016/09/08. 鉴于上表,如果我将客户A指定为我的客户,则公式应标明“是”,因为客户A在2016/09/08购买了苹果和香蕉。
D栏中的内容如下:
=IF(COUNTIFS(A:A,A2,B:B,B2,C:C,"Bananas")+COUNTIFS(A:A,A2,B:B,B2,C:C,"Apples")>=2,"Yes","No")
Using an "array formula" is probably the easiest way to do it: 使用“数组公式”可能是最简单的方法:
Enter the following an instead of just pressing enter, use Control + Shift + Enter. 输入以下内容而不是仅按Enter键,使用Control + Shift + Enter。 If you don't use Control + Shift + Enter it'll just come up with "NO" for every row. 如果你不使用Control + Shift + Enter它会为每一行提出“NO”。
=IF(SUM(IF(A$2:A$8=A2,IF(B$2:B$8=B2,IF(C$2:C$8=C2,1,1),0),0))>1,"YES","NO")
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.