简体   繁体   中英

Generate a 3rd column sequential number based on two columns data

I apologize if the title is misleading, but I have an issue where I need to generate a sequential number in a third column based on comparing data from two different columns.

My data looks like this: Before

The entry with the 1 is the first point, I need to use the value in the 'Back' column to find the same value in the 'Front' Column, then add +1 to the point, so the result looks like:

After

Because of the naming conventions used, sorting either column by value will not work.

Appreciate the help!

Assuming you have the initial 1, and your number column is C, front is D, back is E, this would start at row 2:

=INDEX(C:C,MATCH(INDEX(D:D,MATCH(D2,E:E,0),1),D:D,0),1)+1

Image: http://i.imgur.com/0XfdLrk.png

Did you establish whether your data has duplicates or incomplete sequences?

Here's another formula which should achieve what you want and also doesn't rely on you knowing where the sequence starts. Every sequence will start with 1.

This formula follows your image layout, putting values into column A with data in columns B and C. Please replace the ranges in the formula for columns A and C to cover all of your data. (Ideally, you would do this by inserting a table first and then selecting the data rows, which will cause Excel to put in the table column name instead.)

This is the formula to go into cell A2, assuming you have data in B2:C7

=IF(ISERROR(MATCH(B2,$C$2:$C$7,0)),1,INDEX($A$2:$A$7,MATCH(B2,$C$2:$C$7,0))+1)

Put this formula in D2 and fill down to identify which rows are the ends of sequences:

=ISERROR(MATCH(C2,$B$2:$B$7,0))

Put this formula in E2 and fill down to identify duplicates in the Front column:

=COUNTIF(B$2:B$7,B2)

You can then fill it right one column to also identify duplicates in Back.

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