简体   繁体   English

如果满足某些条件,则标识列表中条目的首次出现(EXCEL)

[英]Identify first occurrence of an entry in a list, if certain criteria is met (EXCEL)

I have spent too much time trying to figure our the question imposed, in the title of this question, and am reaching out for some help. 我花了太多时间试图以问题的标题来说明我们提出的问题,并且正在寻求帮助。

I would like to output an entry of 1 for the first occurrence when criteria is equal to AR and output an entry of 1 for the first occurrence on a column when criteria is equal to SFR on a seperate column. 当条件等于AR时,我想为第一次出现输出1的条目,而当条件等于单独列上的SFR时,我为列的第一次出现的条目输出1。

For example the columns I'd want in the following table are the columns titled AR and SFR 例如,下表中我想要的列是标题为ARSFR的列

|Property Name  | product | company | AR | SFR |
|---------------|---------|---------|----|-----|
|orange grove   |    2    |   SFR   | 0  |  1  |
|orange grove   |    1    |   AR    | 1  |  0  |
|orange grove   |    6    |   AR    | 0  |  0  |
|garden court   |    2    |   SFR   | 0  |  1  |
|garden court   |    1    |   AR    | 1  |  0  |
|chimney sweeps |    6    |   AR    | 1  |  0  |
|chimney sweeps |    2    |   SFR   | 0  |  1  |
|chimney sweeps |    1    |   AR    | 0  |  0  |
|chimney sweeps |    4    |   SFR   | 0  |  0  |
|downing apts   |    2    |   SFR   | 0  |  1  |
|downing apts   |    1    |   SFR   | 0  |  0  |
|downing apts   |    6    |   AR    | 1  |  0  |

I tried implementing countif within my formula and only taking into consideration when my output is a result of 1, then nesting the formula for criteria "AR" or "SFR" with the result of my countif, if the criteria is satisfied, but the table isn't organized so that AR comes first in the table row and vice versa. 我尝试在公式中实现countif ,并且仅在输出为1的情况下才考虑在内,如果条件满足,则将条件“ AR”或“ SFR”的公式与countif的结果嵌套在一起,但是该表没有进行组织,因此AR在表格行中排名第一,反之亦然。 Here is an example of my formula: 这是我的公式的一个示例:

=IF(E2="AR", IF(COUNTIF($C$2:C2,C2)=1,1,""), "")

Sometimes I'll have instances where the company name occurs but the count isn't 1. Take for example orange grove . 有时,我会遇到一些公司名称出现而公司数目却不是1的情况。例如, orange grove Orange grove's count would be 1, 2, 3 consecutively, for each +1 instance. 对于每个+1实例,Orange Grove的计数将连续为1、2、3。 If my count is 1 and SFR , my formula would output a 1 but if my criteria is AR and the count is not 1 (it's actually 2 or 3), I don't get a first occurrence output per my criteria of AR . 如果我的计数是1和SFR ,则我的公式将输出1,但是如果我的标准是AR ,并且计数不是1(实际上是2或3),则我的AR准则不会产生第一个出现的输出。

I saw there may be a way to utilize sumproduct but I am not familiar with it. 我看到可能有一种利用sumproduct的方法,但我并不熟悉。

Could anyone please help. 谁能帮忙。 Anything would be appreciated! 任何事情将不胜感激!

It would guanrantee you a result if you could CONCATENATE the Property Name and Company and then input the below mentioned formula into AR and SFR cells. 这将guanrantee你一个结果,如果你能CONCATENATE的属性名称和公司,然后输入以下提到的公式为ARSFR细胞。

  1. Insert a column and use =CONCATENATE(A2," ",C2) to merge Product Name and Company. 插入一列,然后使用=CONCATENATE(A2," ",C2)合并产品名称和公司。 It should give you result in space delimited format. 它应该给您结果以空格分隔的格式。 For eg. 例如。 orange grove SFR, chimney sweeps AR, etc. 橘树林SFR,烟囱扫AR等
  2. Enter this formula in Cell E2 which belongs under AR column: =IF(TRIM(RIGHT($D2,3))=E$1,IF(OR(COUNTIF($D:$D,$D2)=1,MATCH($D2,$D:$D,0)>=ROW($D2)),1,0),0) 在属于AR列的单元格E2中输入此公式: =IF(TRIM(RIGHT($D2,3))=E$1,IF(OR(COUNTIF($D:$D,$D2)=1,MATCH($D2,$D:$D,0)>=ROW($D2)),1,0),0)
  3. Drag the formula left onto Cell F2 to apply to SFR column and then to the bottom of each columns to apply for all records/rows. 将公式向左拖动到单元格F2上以应用到SFR列,然后将其拖到每列的底部以应用所有记录/行。

In the end you will have the following result as expected: 最后,您将获得预期的以下结果:

Table: 表:

R/C   A               B         C        D                    E     F

01    Property Name   product   company  Merged PN + C        AR    SFR
-------------------------------------------------------------------------
02    orange grove    2         SFR      orange grove SFR     0     1
03    orange grove    1         AR       orange grove AR      1     0
04    orange grove    6         AR       orange grove AR      0     0
05    garden court    2         SFR      garden court SFR     0     1
06    garden court    1         AR       garden court AR      1     0
07    chimney sweeps  6         AR       chimney sweeps AR    1     0
08    chimney sweeps  2         SFR      chimney sweeps SFR   0     1
09    chimney sweeps  1         AR       chimney sweeps AR    0     0
10    chimney sweeps  4         SFR      chimney sweeps SFR   0     0
11    downing apts    2         SFR      downing apts SFR     0     1
12    downing apts    1         SFR      downing apts SFR     0     0
13    downing apts    6         AR       downing apts AR      1     0

Explanation: 说明:

  1. We merged Product Name & Company to identify unique records. 我们合并了产品名称和公司,以标识唯一记录。
  2. Then we created a condition to check for last 3 characters to match our column name: =IF(TRIM(RIGHT($D2,3))=E$1 然后,我们创建了一个条件以检查最后3个字符是否与我们的列名匹配: =IF(TRIM(RIGHT($D2,3))=E$1
  3. If the above condition is true which means that we are in the correct Company column, we can now proceed to check if the Product Name instance is first or not. 如果以上条件为真,则意味着我们在正确的“公司”列中,我们现在可以继续检查“产品名称”实例是否为“第一”。 If not, then we are in the wrong column so just print 0. 如果不是,那么我们在错误的列中,因此仅打印0。
  4. As you mentioned there can be either a unique combination or multiple combinations of Product Name & Company. 如您所述,产品名称和公司可以是唯一组合,也可以是多个组合。 Therefore there are 2 conditions: a. 因此,有两个条件: When combination is unique ie count is equal to 1: COUNTIF($D:$D,$D2)=1 b. 如果组合是唯一的,即计数等于1: COUNTIF($D:$D,$D2)=1 b。 When combination is duplicate but row number of first instance is less than equal to current row number: MATCH($D4,$D:$D,0)>=ROW($D4) 当组合重复但第一个实例的行号小于当前行号时: MATCH($D4,$D:$D,0)>=ROW($D4)
  5. If either of the above 2 conditions are TRUE then the record is first instance and hence print 1, else it is not and hence print 0. 如果以上两个条件中的任何一个为TRUE,则记录为第一实例,因此显示为1,否则为0,因此记录为0。

Hope it helped. 希望能有所帮助。

Assuming Column D and E are where your AR and SFR columns are respectively, try: 假设D列和E列分别是AR和SFR列所在的位置,请尝试:

Table Structure: 表结构:

    AR  SFR
AR  1   0
AR  0   0
AR  0   0
AR  0   0
AR  0   0
SFR 0   1

Cell D2 Would be (assuming AR is your column Header for column D) 单元格D2将是(假设AR是列D的列标题)

=IF(C2=D1,1,0)

E2 Would be: E2将是:

=IF(C2=E1,1,0)

For D3, then drag down for each cell in column D 对于D3,然后向下拖动D列中的每个单元格

=IF(SUM(D$2:D2)=0,IF($C3=D$1,1,0),0)

For E3, then drag down for each cell in column E 对于E3,然后向下拖动E列中的每个单元格

IF(SUM(E$2:E2)=0,IF($C3=E$1,1,0),0)

Thanks! 谢谢!

Ryan 瑞安

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

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