简体   繁体   English

计算唯一文本值的SUMPRODUCT

[英]SUMPRODUCT that counts unique text values

I have a data set that roughly looks like this: 我有一个大致如下所示的数据集:

OpenDate      Name      FillDate      DaysToFill
12/05/13      Samuel        -           Open
01/01/14      Anne      01/16/14        16
01/12/14      Mike      01/25/14        13
01/28/14      Anne      01/31/14         3

I have a dashboard I am creating for metrics. 我有一个要为指标创建的仪表板。 There is a data validation list in which the user picks the month they want information about. 有一个数据验证列表,用户可以在其中选择所需信息的月份。 This choice triggers a change in two cells -- R2 and R3. 此选择触发两个单元(R2和R3)中的更改。 R2 corresponds to the month and generates the numeric value of that month (Jan =1, Feb = 2, etc) and R3 generates the last day in that month for the current year (Jan = 01/31/14, Feb = 02/28/14). R2对应于月份并生成该月的数值(Jan = 1,Feb = 2,依此类推),R3生成当前年份该月中的最后一天(Jan = 01/31/14,Feb = 02 / 28/14)。

I have a formula that counts the number of entries that meet EITHER of the conditions below: 我有一个公式来计算满足以下条件的条目数:

(i) DaysToFill > 0  AND FillDate is in the month chosen (in R2)

OR 要么

(ii) DaysToFill = "Open" AND OpenDate < last day of month chosen (in R3)

I currently have the following sumproduct formula that calculates this: 我目前有以下sumproduct公式来计算:

=SUMPRODUCT(--(ISNUMBER(DATA!I2:I30)),--(MONTH(DATA!I2:I30)=Sheet1!R2),

--(DATA!J2:J30>0))+SUMPRODUCT(--(ISNUMBER(DATA!C2:C30)),

--((DATA!C2:C30)<=Sheet1!R3),--(DATA!J2:J30="Open"))

Where 哪里

Column C = OpenDate; C列= OpenDate; Column I = FillDate; 第I列= FillDate; Column J = DaysToFill, and Column H (which isn't used here) is Name J列= DaysToFill,H列(此处未使用)为Name

This all works fine, but I need a way to add the condition on the above formula -- I need a way to count the unique Names that meet those conditions. 一切正常,但是我需要一种在上述公式上添加条件的方法-我需要一种计算满足这些条件的唯一名称的方法。 So for the above data, if the user chooses January, the output for the formula I have is 4 [3 that meet the conditions in (i) and 1 that meets the conditions in (ii)]. 因此对于上述数据,如果用户选择一月,则公式I的输出为4 [3满足(i)中的条件,1满足(ii)中的条件]。 But, if we get the additional layer of unique recruiters, I should get 3 (Because Anne is counted twice). 但是,如果我们得到了更多的独特招聘人员,我应该得到3(因为安妮被计算了两次)。 I'm having a hard time seeing how to approach this. 我很难看到如何解决这个问题。 Any help is appreciated. 任何帮助表示赞赏。

You can use this "array formula" 您可以使用此“数组公式”

=SUM(IF(FREQUENCY(IF(ISNUMBER(DATA!I2:I30)*(MONTH(DATA!I2:I30)=Sheet1!R2)*(DATA!J2:J30>0)+ISNUMBER(DATA!C2:C30)*(DATA!C2:C30<=Sheet1!R3)*(DATA!J2:J30="Open"),IF(H2:H30<>"",MATCH(H2:H30,H2:H30,0))),ROW(H2:H30)-ROW(H2)+1),1))

confirmed with CTRL + SHIFT + ENTER 使用CTRL + SHIFT + ENTER确认

Note that I'm not sure if your original formula has a flaw because DATA!J2:J30>0 will return TRUE for any cells that contain "Open". 请注意,我不确定您的原始公式是否有缺陷,因为DATA!J2:J30>0将对包含“打开”的任何单元格返回TRUE Does that extra condition achieve anything, if J2:J30 always contains a date or "Open" that part will return TRUE for everything..... 如果J2:J30始终包含日期或“打开”,那么该额外条件是否会实现任何效果,该零件将对所有内容返回TRUE。

Quick thoughts: - Create a flag column that catenates the name and if the row matches the selection criteria. 快速思考:-创建一个标志列,该标志列用于填充名称,并且该行是否符合选择条件。 First entry for example would be "Samuel.True" In next column create enter the following formula 例如,第一个条目是“ Samuel.True”。在下一列中,输入以下公式

=if(row(<cell where name is>) = match(<cell where name is>&".True",<entire column created above>,0),1,0)

The idea being it will return 1 if it is the first matching name and valid selection, and 0 if not. 如果它是第一个匹配名称和有效选择,它将返回1,否则返回0。

You can then sum that column and get the total of unique names that match the filter criteria. 然后,您可以对该列求和并获得与过滤条件匹配的唯一名称的总数。

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

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