Create New Unique ID Based on Two Columns - Excel

|▌冷眼眸甩不掉的悲伤 提交于 2021-02-11 10:03:47

问题


I have a problem at work where we would take an old SKU number and replace it with a new one. Unfortunately, there are instances where the new SKU number replacing an old SKU number would eventually become an 'old' SKU itself and would be phased out. Below is an example.

    Old Sku   New SKU
    06223     34162
    06223     34162
    06553     01925
    06557     19100
    06557     19100
    06573     11443
    06573     11443
    51095     06223
    51095     06223

With the way I need it formatted for work, I need the three different SKU's to become 1 unique SKU, so 06223, 34162, and 51095 would equal a new SKU # of 12345.

This is what I would need it to look like

    Old Sku New SKU Unique SKU
    06223   34162   1
    06223   34162   1
    06223   34162   1
    06553   01925   2
    06557   19100   3
    06557   19100   3
    06573   11443   4
    06573   11443   4
    51095   06223   1
    51095   06223   1

I am not too familiar with the indirect function but I have been told I may need to use that. I appreciate all the help. Thank you!

EDIT @CallumDA this is what I am getting with your code

    Old SKU         New SKU         All New SKU
    00080           00080           1
    00606           24264           2
    00606           98952           3
    00644           16814           4
    00721           58008           5
    00753           01929           6

Rows 2 and 3 should have 2 in the all new sku


回答1:


Place this formula into C2 and drag down

=IFERROR(VLOOKUP(IFERROR(VLOOKUP(B3,$A$1:$B1,2,0),B2),$B$1:$C1,2,0),MAX($C$1:C1)+1)

Which looks like this:

As I was suggesting in the comments, you might also be fine with a simpler solution:

=IFERROR(VLOOKUP(B2,$A$2:$B$11,2,0),B2)

Which just gets the latest New SKU -- like this: (in the "Alternative" column)

Update

Since you updated your data you have a one-to-many relationship as well as many-to-one. Here is the updated method and formula. I changed the value in cell B3 for this scenario and split it into two columns for ease:

The formula in D2 is:

=VLOOKUP(INDEX($A$2:$A$11,MATCH(IFERROR(VLOOKUP(B2,$A$2:$B$11,2,0),B2),$B$2:$B$11,0)),$A$2:$B$11,2,0)

And likewise for E2 is:

=IFERROR(VLOOKUP(D2,$D$1:$E1,2,0),MAX($E$1:E1)+1)

Your updated data now looks like this:



来源:https://stackoverflow.com/questions/42072127/create-new-unique-id-based-on-two-columns-excel

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!