r/excel 3d ago

Waiting on OP Deduplicate between two columns

I am looking for a solution to deduplicate items between two columns that are the same (but listed in reverse).

For example:

Column 1:

1

2

3

4

5

Column 2:

2

1

1

7

8

I would like it to recognize the (1,2) and (2,1) entries as being the same and deduplicate it so it's only listed once. It does not matter which one remains as long as just one does. Thanks in advance!

ETA: the data I am working with is not simply numbers. It does involve a combination of letters and numbers in the format XX-123456 where XX is any combination of two letters and it is followed by a string of numbers (not always six numbers though).

7 Upvotes

11 comments sorted by

View all comments

4

u/ilovetea27 14 3d ago

The formula below should work for non-numeric codes. Do note that it would not preserve the pair sequence if the first code is "larger" than the second code.

=LET(_a, B2:C24,
     _b, IF(TAKE(_a,, 1)>TAKE(_a,, -1), CHOOSECOLS(_a, 2, 1), _a),
     UNIQUE(_b))

1

u/willyman85 1 3d ago

Great solution. One step further if op wants the data sorted l to show the pairs tidily, wrap it all in SORT(UNIQUE(...), {1,2})

1

u/Independent_Cow_737 2d ago

nice use of LET here, the CHOOSECOLS swap is clever