简体   繁体   中英

Need help in generating a formula for nextID excel column

I have a an excel sheet with the following columns ID, City, Record no. I need to generate a column called Next ID based on the record number. ie if the city is same I need to populate the Next ID column with the ID of the previous record number.

Is there a way to do this in 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

在此处输入图片说明


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)),"")

在此处输入图片说明

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

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