简体   繁体   English

计算满足多个条件的行数

[英]Count number of rows where multiple criteria are met

I'm trying to generate a table that shows a count of how many items are in any given status on any given day. 我正在尝试生成一个表,该表显示在任何给定的一天中处于给定状态的物品数量。 My result table has a set of Dates down column A and column headers are various statuses. 我的结果表在A列下有一组Dates,列标题是各种状态。 A sample of my data table with headers looks like this: 我的带有标题的数据表的示例如下所示:

Product | Notice | Assigned | Complete | In Office | In Accounting 
   1    | 5/5/13 |  5/7/13  | 5/9/13   |  5/10/13  |    5/11/13 
   2    | 5/5/13 |  5/6/13  | 5/8/13   |  5/9/13   |    5/10/13
   3    | 5/6/13 |  5/9/13  | 5/10/13  |  5/10/13  |    5/10/13 
   4    | 5/4/13 |  5/5/13  | 5/7/13   |  5/8/13   |    5/9/13 
   5    | 5/7/13 |  5/8/13  | 5/10/13  |  5/11/13  |    5/11/13

If my output table were to contain a set of dates in the first column with the statuses as headers, I need a count of how many rows were at the given status and had not yet transitioned to the next status so that in the Notice column, I'd have a count of rows where the Notice Date was <= X AND where the Assigned, Complete, In Office, In Accounting are all greater than X. 如果我的输出表在第一列中以状态作为标题包含一组日期,则我需要计算处于给定状态但尚未转换为下一个状态的行数,因此在“通知”列中,我要计算通知日期小于等于X的行数,并且已分配,完成,在办公室,在会计中的行都大于X。

I've used a Sum(if(frequency(if statement to get me REALLY close but I feel like I need to have an AND statement within the second IF like this =SUM(IF(FREQUENCY(IF(AND 我已经使用了Sum(if(frequency(if语句让我非常接近,但是我觉得我需要在第二个IF内有一个AND语句,例如=SUM(IF(FREQUENCY(IF(AND

Here's what I have that won't work: 这是我无法使用的内容:

=SUM(IF(FREQUENCY(IF(AND(Table1[Assigned]<=A279,Table1[[Complete]:[In Accounting]]<=A279),ROW(Table1[[Complete]:[In Accounting]])),ROW(Table1[[Complete]:[In Accounting]]))>0,1))

If I take the "AND" portion out, this works fine except I need it to ONLY count rows where the given status actually has a date so if an "Assigned" date is empty, I don't want that row to be counted for the Assigned column. 如果我取出“ AND”部分,则可以正常工作,只是我只需要计算给定状态实际上具有日期的行,因此,如果“ Assigned”日期为空,则我不希望对该行进行计数已分配列。

Here's an example of what I'd expect to see in the results. 这是我期望在结果中看到的示例。 I've listed the count in the each column as well as the corresponding product numbers in parenthesis. 我已经在每列中列出了计数,并在括号中列出了相应的产品编号。 The corresponding product numbers are for reference only and won't actually be in the result table. 相应的产品编号仅供参考,实际上不会出现在结果表中。

Date | Notice  | Assigned | Complete
 5/6 | 2 (1,3) | 2 (2,4)  |  0
 5/7 | 2 (3,5) | 2 (1,2)  |  1 (4)
 5/8 | 1 (3)   | 2 (1,5)  |  1 (2)

OK, assuming you have the original data in A1:F6 then with 2nd table headers in B9:D9 and row labels in A10:A12 then you can use this "array formula" in B10 好的,假设您在A1:F6中具有原始数据,然后在B9:D9中具有第二个表头,在A10:A12中具有行标签,则可以在B10中使用此“数组公式”

=SUM((B$2:B$6<=$A10)*(MMULT((C$2:$F$6>$A10)+(C$2:$F$6=""),TRANSPOSE(COLUMN(C$2:$F$6)^0))=COLUMNS(C$2:$F$6)))

confirmed with CTRL + SHIFT + ENTER and copied down and across (see screenshot below) 使用CTRL + SHIFT + ENTER确认并向下复制并复制(请参见下面的屏幕截图)

As you can see the results are as per your requirement. 如您所见,结果符合您的要求。 If you replace dates with blanks it will still work 如果您将日期替换为空白,它将仍然有效

MMULT is a way to get a single value from each row even when you are looking at multiple columns. MMULT是一种即使在查看多列时也可以从每一行获取单个值的方法。

I used cell references because I think that's easier, especially when copying the formula across and having a reducing range.......but you can use structured references if you want 我使用了单元格引用,因为我认为这更容易,尤其是在跨范围复制公式并减小范围的情况下.......但是如果需要,您可以使用结构化引用

在此处输入图片说明

Have you tried using COUNTIFS to count based on multiple criteria. 您是否尝试过使用COUNTIFS根据多个条件进行计数。 It is fairly well documented here: http://office.microsoft.com/en-us/excel-help/countifs-function-HA010047494.aspx (2007+ only) 它在这里有很好的记录: http ://office.microsoft.com/zh-cn/excel-help/countifs-function-HA010047494.aspx(仅2007年以上)

Basically, you use it like 基本上,您可以像

=COUNTIFS(first_range_to_check, value_you_want_in_first_range, ...)

where the ... represents as many pairs as you want (up to 127 total pairs), note the conditions are AND connection so if you have two pairs, the first pair AND the second pair must return true for that row to count. 其中...表示任意数量的对(最多127个对),请注意条件是AND连接,因此,如果有两对,则第一对AND第二对必须返回true才能计数该行。

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

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