简体   繁体   English

需要帮助为nextID excel列生成公式

[英]Need help in generating a formula for nextID excel column

I have a an excel sheet with the following columns ID, City, Record no. 我有一个具有以下列ID,城市,记录号的Excel工作表。 I need to generate a column called Next ID based on the record number. 我需要根据记录号生成一个名为“下一个ID”的列。 ie if the city is same I need to populate the Next ID column with the ID of the previous record number. 也就是说,如果城市相同,则需要使用上一个记录编号的ID填充“下一个ID”列。

Is there a way to do this in excel? 有没有办法在excel中做到这一点?

Here is the sample data, with the Next Column populated manually for reference: 以下是示例数据,并手动填充了“下一列”以供参考:

ID  City    Record no.  **Next ID
121 Paris     3 
122 Paris     2          121
123 Paris     1          122
124 New York  2 
125 New York  1          124

Please see attached image 请看附件图片

样本数据供参考

I've edit the question as I was not able to add a image in the comments. 我无法编辑图片,因此无法编辑图片。 My data is not sorted so I used the second formula. 我的数据未排序,因此我使用了第二个公式。 This works for some cases but doesn't work for others. 这在某些情况下有效,但在其他情况下则无效。 see the pink colored cells which should have a value but do not. 看到粉红色的单元格应该有一个值,但没有。 使用公式后

If your data is always sorted use this: 如果您的数据始终排序,请使用以下命令:

=IF(B2=B1,A1,"")

in D2 and copy/drag down 在D2中复制并拖动

在此处输入图片说明


If not sorted then use this: 如果未排序,请使用以下命令:

=IFERROR(INDEX(A:A,AGGREGATE(15,6,ROW($C$2:$C$6)/(($C$2:$C$6=C2+1)*($B$2:$B$6=B2)),1)),"")

在此处输入图片说明

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

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