简体   繁体   English

尝试使用SUMPRODUCT根据另外两个条件识别唯一值?

[英]Trying to use SUMPRODUCT to identify unique values based on two additional conditions?

I am having some difficulty with this formula and I am hoping someone can help. 我对这个公式有些困难,我希望有人可以提供帮助。 I have searched extensively everywhere I can think of and can't find an answer pertaining directly to this issue. 我已经在我能想到的任何地方进行了广泛的搜索,并且找不到与此问题直接相关的答案。 I have data in a spreadsheet table tracking employee assigned tasks and am focusing on three fields: the employee name (Employee Name), the date the employee was assigned a task (Employee Assigned Date) and the month and year the employee was assigned the task (Task Month Year). 我在电子表格表中有数据跟踪员工分配的任务,并关注三个字段:员工姓名(员工姓名),员工分配任务的日期(员工分配日期)以及员工分配任务的月份和年份(任务月份)。

I am trying to identify the unique assigned dates for a given employee in a given month/year. 我正在尝试确定给定员工在给定月份/年中的唯一指定日期。 So in the example below, John Smith would return three unique dates for March 2017, since 03/05/2017 and 03/14/2017 repeat. 因此,在下面的示例中,John Smith将返回2017年3月的三个独特日期,自03/05/2017和03/14/2017重复。

Employee Name        Employee Assigned Date        Task Month Year
Paul Martin          03/01/2017                    March 2017
James Smith          03/05/2017                    March 2017
James Smith          03/05/2017                    March 2017
James Smith          03/06/2017                    March 2017
James Smith          03/14/2017                    March 2017
James Smith          03/14/2017                    March 2017

The formula that I have come up with is as follows: 我提出的公式如下:

=SUMPRODUCT((Table2[Employee Name]=”James Smith”)*(Table2[Task Month Year]")=”March 2017”/(COUNTIF(Table2[Employee Assigned Date],Table2[Employee Assigned Date]&"")))

I have stripped out some pieces of the formula that convert month date to text, etc. so the issue is not around that. 我已经删除了一些将月份日期转换为文本等的公式,所以问题不在于此。 If I sumproduct the employee name and task month year section by itself, I get the correct answer for the total of James Smith's assigned tasks, five. 如果我自己产生员工姓名和任务月份部分,我会得到詹姆斯史密斯分配的任务总数的正确答案,五个。 If I remove the Employee Name piece I get the correct answer for unique dates in March 2017 for all employees, four. 如果我删除员工姓名部分,我会在2017年3月为所有员工获得4个独立日期的正确答案。

Any help with this would be greatly appreciated, I'm assuming I am doing something stupid but I've been working on this for hours and can't seem to find the solution on my own. 对此有任何帮助将非常感激,我假设我做了一些愚蠢的事情,但我已经在这个工作了几个小时,似乎无法找到我自己的解决方案。

Thank you! 谢谢!

You can do this by removing duplicates. 您可以通过删除重复项来完成此操作。 If you need to retain the original data, then of course copy and paste it to a new tab first. 如果您需要保留原始数据,那么当然要先将其复制并粘贴到新标签中。

In the Data tab, select Remove Duplicates. 在“数据”选项卡中,选择“删除重复项”。 Then in the pop-up box, make sure you select all 3 of your columns, presumably A, B and C from the way you laid it out above. 然后在弹出框中,确保从上面的布局中选择所有3列,大概是A,B和C. This will make sure that duplicates matching all 3 columns will be removed, giving you a list of unique assignment dates per employee, per month/year combination. 这将确保删除与所有3列匹配的重复项,为您提供每个员工,每月/每年组合的唯一分配日期列表。

COUNTIF will return the wrong values in your suggested formula because the name criteria isn't included in that part. COUNTIF将在您建议的公式中返回错误的值,因为该部分中不包含名称标准。 One solution is to include the name criteria in an expanded COUNTIFS like this: 一种解决方案是在扩展的COUNTIFS包含名称标准,如下所示:

=SUM(IFERROR((Table2[Task Month Year]="March 2017")/(Table2[Employee Name]="James Smith")/COUNTIFS(Table2[Employee Assigned Date],Table2[Employee Assigned Date],Table2[Employee Name],"James Smith"),0))

confirm with CTRL+SHIFT+ENTER CTRL+SHIFT+ENTER

.....or you can fall back on the old FREQUENCY approach, ie .....或者你可以依靠旧的FREQUENCY方法,即

=SUM(IF(FREQUENCY(IF(Table2[Task Month Year]="March 2017", IF(Table2[Employee Name]="James Smith",IF(Table2[Employee Assigned Date]<>"",MATCH(Table2[Employee Assigned Date],Table2[Employee Assigned Date],0)))),ROW(Table2[Employee Assigned Date])-MIN(ROW(Table2[Employee Assigned Date]))+1),1))

also confirm with CTRL+SHIFT+ENTER 也用CTRL+SHIFT+ENTER

Both should give the same answer 两者都应该给出相同的答案

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

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