简体   繁体   English

在Excel中找到匹配行的最后一个值

[英]finding last value with matching row in excel

I want to find out last occurrence of particular value and if it is there apply some formula. 我想找出特定值的最后一次出现,如果有,则应用一些公式。

Machine Starttime             Alert
a       10/19/2016 12:16:15   S
a       10/19/2016 12:18:15   E
a       10/19/2016 12:19:20   S
b       10/19/2016 12:21:45   S
b       10/19/2016 12:21:48   S
b       10/19/2016 12:21:55   E
a       10/19/2016 12:23:15   S
a       10/19/2016 12:27:30   E

Machine column will have machine name, Starttime is log time of that particular event and alert can be start of End. “计算机”列将具有计算机名称,“开始时间”是该特定事件的日志时间,而警报可以是“结束”的开始。

I need output like following: 我需要如下输出:

Machine Starttime   Alert   Difference
a   10/19/2016 12:16:15 S   
a   10/19/2016 12:18:15 E   120
a   10/19/2016 12:19:20 S   
b   10/19/2016 12:21:45 S   
b   10/19/2016 12:21:48 S   
b   10/19/2016 12:21:55 E   10
a   10/19/2016 12:23:15 S   
a   10/19/2016 12:27:30 E   490

Difference will be populated only in case of E and there is corresponding start event for that machine, if there are more than one start event then pick first one. 仅在E的情况下才会填充差异,并且该机器有相应的启动事件,如果启动事件不止一个,则选择第一个。 I just want to understand if it is possible with just excel formula(without macro)? 我只想了解是否可以仅使用Excel公式(不使用宏)? if yes, how? 如果是,如何?

I already tried it using index function without success 我已经使用索引功能尝试过但没有成功

=IF(C3="E",MATCH(A3,A2:$A$2,0),"")

Yes it is possible but it is not easy. 是的,有可能,但并不容易。 You have to use an array formula to solve this. 您必须使用数组公式来解决此问题。 The formula would be: 计算公式为:

=IF(C2="S","",(B2-MIN(IF($A$2:A2=A2,IF($C$2:C2="S",IF(ROW($A$2:A2)>MAX(IF(ROW($A$2:A2)<ROW(A2),IF($A$2:A2=A2,IF($C$2:C2="E",ROW($A$2:A2))))),$B$2:B2)))))*86400)

First data row is 2, column A has the machine names, column B the log times, column c the "S"/"E". 第一个数据行为2,列A为机器名称,列B为日志时间,列C为“ S” /“ E”。 Put the formula in column D in the first data row and push CTRL+SHIFT+ENTER to make it an array formula. 将公式放在第一个数据行的D列中,然后按CTRL + SHIFT + ENTER使其成为数组公式。 You should see {} around the formula now. 您现在应该在公式周围看到{} Copy the cell (CTRL+C) and paste it into all rows except the row where the formula is already in. 复制单元格(CTRL + C),然后将其粘贴到公式所在的行以外的所有行中。

If you need any more help, place a comment. 如果您需要更多帮助,请发表评论。

It can be done with some complicated array formula, but a helper formula can make it easier to distinguish the groups. 可以使用一些复杂的数组公式来完成,但是使用辅助公式可以使区分组更加容易。 For example in D2 : 例如在D2

= ( ABS(N(D1))+($A2<>$A1) ) * IF(C2="S",1,-1)

and the final Index + Match formula next to it in E2 : 以及E2旁边的最终Index + Match公式:

=IF($C2="E", ROUND( ($B2 - INDEX($B$2:$B$9, MATCH(ABS($D2),$D$2:$D$9,0) ) )*24*60*60,0),"")

With your sample data, it should result in something like this: 使用您的样本数据,结果应该是这样的:

A       B                   C       D       E
-----------------------------------------------------------
Machine Starttime           Alert   Group   Index+Match
a       10/19/2016 12:16    S        1      
a       10/19/2016 12:18    E       -1      120
a       10/19/2016 12:19    S        1      
b       10/19/2016 12:21    S        2      
b       10/19/2016 12:21    S        2      
b       10/19/2016 12:21    E       -2      10
a       10/19/2016 12:23    S        3      
a       10/19/2016 12:27    E       -3      255

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

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