SOLVED

Matching pair of values in two columns

Copper Contributor

Hi everyone,
There is a table where some data are stored in one columned, but it may happen that the same data could be found in the second column. I need to pair thouse entries and declare them as having equal meaning by grouping them in the third column, like given below. Note that the entries in "Group" column are done manualy.

Prod_1Prod_2Group
00214087561
00214142671
00273097832
00278118913
08756002141
09783002732
11891002783
14267002141

 

So, I'm asking for the formula, which will help me to generate group numbers for "Group" column over all record set vithout any VBA coding.

Thanks in advance,

13 Replies
One more commnet: For the same pairs group number can be "Prod_1" & "Prod_2"

@George_Jokha 

The attached file lists the unique products from both columns in i3#

bosinander_0-1645438282150.png

c2# looks for matches in i3#

=LET(prod1;A2:A9;
     prod2;B2:B9;
match1;XMATCH(prod1;I3#);
match2;XMATCH(prod2;I3#);
output;IF(match2<match1;match2;match1);
output
)

The vstack in i3 is done by

=LET(list1;A2:A100000;
     list2;B2:B100000;
maxRows;MAX(ROWS(list1);ROWS(list2));
seq;SEQUENCE(maxRows*2;;0);
row;MOD(seq;maxRows)+1;
loop;INT(seq/maxRows)+1;
dimensions;CHOOSE(loop;
   INDEX(list1;row;SEQUENCE(1;COLUMNS(list1)));
   INDEX(list2;row;SEQUENCE(;COLUMNS(list2))));
output;UNIQUE(dimensions);
output
)

 If you want to debug the LET function, change the last line from output to as maxRows and you will see the result from that part.

Hmm, very interesting. Does it work for text values also? because, for some reason, when I put the text Products codes then the formula give an error

@George_Jokha Seems ok with version 2201 (Excel 365, jan 2022).

 

bosinander_1-1645440069934.png

In cell i3, you may want to add sort but it will give you different group numbers. If group name is important you can use XLOOKUP instead of XMATCH (in attached file)

output;SORT(UNIQUE(dimensions));

@bosinander Thank you very much. It seems to be good dessision. Difficult, but good! :))

But.. ooh, "x" formulas seems to work only for higher version of the windows. I have windows 10 :(
You're welcome :)
XMATCH and XLOOKUP are not very new but quite. Both of the are available without X and be functional in this case. But... LET, SEQUENCE and UNIQUE takes more effort to implement in older versions. 365 holds the latest possibilities, inluding the fantastic lambda (different chapter since it so far is not in use here).

@bosinander Hi (Good morning from me :) )

 

I have tried many times to apply formulas you've provided, but unfortunately, my system bocks the excel with "No responding" result.

 

Is it possible to upload my file (about 350 rows in total, two columns) and you could help me to group the pairs? If it won't bother you much...


P.S. BTW - I can not find the button here to upload the any excel file, as you did.

best response confirmed by George_Jokha (Copper Contributor)
Solution

@George_Jokha 

 

When you click "reply" you have a link to the left above the Post button where you can open full text editor.

bosinander_0-1645514534444.png

Well there you can attach the file just above the Post Button.

Make sure there is no names or secret data in it and I will take a look.

 

@bosinander I'm newby here (I'm active in Power BI community mainly), so, unfortunately, I could not find the corresponding upload (attachment) button. What I can do is to provide the list in a table:

Prod_1Prod_2
0021408756
0021414267
0027309783
0027811891
0028409829
0028509829
0036609526
0059212174
0131102149
0131203771
0131212659
0131406377
0133610416
0148810415
0156812309
0156907137
0157007138
0157008624
0157011417
0157111418
0157112162
0158107489
0158107859
0158107869
0158208319
0158307877
0158307883
0159111219
0159310428
0184210714
0184310061
0184311228
0198704509
0198707412
0198711230
0199608318
0214901311
0223411567
0331011235
0335810486
0336508153
0343710885
0358611920
0377101312
0385412567
0386811921
0387712560
0387812562
0387814652
0388012563
0388212526
0388214403
0388308004
0388314486
0388408010
0410812170
0450901987
0479006481
0510211891
0511205113
0511212048
0511305112
0529612327
0565211234
0570509783
0583012807
0583107363
0583910281
0603212168
0617012470
0617014288
0617312806
0637701314
0637714484
0642610997
0647910414
0648104790
0648110417
0658510492
0660910487
0660914297
0713701569
0713801570
0714213485
0714214261
0719912807
0729611920
0733308006
0733408006
0733508006
0733608006
0733712319
0733812319
0734712346
0736305831
0741201987
0744411235
0748901581
0785409829
0785810714
0785901581
0786810714
0786901581
0787110714
0787311234
0787701583
0788301583
0793811237
0794009783
0797609925
0797610033
0797610208
0797611577
0799112161
0799612328
0799712327
0800312561
0800314378
0800403883
0800607333
0800607334
0800607335
0800607336
0800612311
0801003884
0801812560
0802012561
0802014378
0802411375
0802411376
0803211221
0803311224
0815303365
0815312701
0831801996
0831901582
0832011219
0862401570
0875600214
0876109829
0876312470
0876314288
0876712532
0876714379
0884912330
0896212702
0897209910
0898312527
0952600366
0970612327
0977411891
0978300273
0978305705
0978307940
0978311011
0982900284
0982900285
0982907854
0982908761
0991008972
0992412328
0992507976
1000412585
1002312170
1003307976
1006101843
1006211235
1020412174
1020807976
1026712307
1027713050
1028010714
1028105839
1041406479
1041501488
1041601336
1041706481
1041811234
1042801593
1042910962
1047410784
1048603358
1048706609
1049206585
1066811222
1067011221
1067311223
1067511224
1071401842
1071407858
1071407868
1071407871
1071410280
1071412339
1071414327
1071414398
1071414456
1073612560
1078212560
1078410474
1078612561
1078614378
1088503437
1091411373
1091412343
1091414664
1095912406
1096210429
1096311117
1099706426
1099712564
1099712565
1099812562
1099814652
1101109783
1111613485
1111614261
1111710963
1121901591
1121908320
1121912312
1121912341
1122108032
1122110670
1122112866
1122113503
1122114298
1122114406
1122114407
1122210668
1122212865
1122213502
1122214408
1122214409
1122310673
1122312867
1122313504
1122314411
1122314413
1122408033
1122410675
1122412868
1122413505
1122414412
1122512168
1122801843
1123001987
1123405652
1123407873
1123410418
1123503310
1123507444
1123510062
1123707938
1137213485
1137214261
1137310914
1137314263
1137508024
1137608024
1141701570
1141801571
1156702234
1157707976
1189100278
1189105102
1189109774
1192003586
1192007296
1192103868
1204805112
1216107991
1216114286
1216201571
1216806032
1216811225
1217004108
1217010023
1217014252
1217400592
1217410204
1217412345
1230710267
1230714319
1230714490
1230901568
1231108006
1231211219
1231412563
1231907337
1231907338
1232705296
1232707997
1232709706
1232712334
1232712555
1232807996
1232809924
1233008849
1233412327
1233910714
1234111219
1234310914
1234314263
1234512174
1234607347
1240610959
1247006170
1247008763
1247012556
1247012558
1247014393
1247014395
1252603882
1252708983
1253208767
1255512327
1255612470
1255614288
1255812470
1255814288
1256003877
1256008018
1256010736
1256010782
1256014378
1256108003
1256108020
1256110786
1256203878
1256210998
1256303880
1256312314
1256410997
1256510997
1256703854
1258510004
1265901312
1270108153
1270208962
1270214318
1280606173
1280705830
1280707199
1286511222
1286611221
1286711223
1286811224
1305010277
1348507142
1348511116
1348511372
1350211222
1350311221
1350411223
1350511224
1425212170
1426107142
1426111116
1426111372
1426311373
1426312343
1426700214
1428612161
1428806170
1428808763
1428812556
1428812558
1429706609
1429811221
1431812702
1431912307
1432710714
1437808003
1437808020
1437810786
1437812560
1437908767
1439312470
1439512470
1439810714
1440303882
1440611221
1440711221
1440811222
1440911222
1441111223
1441211224
1441311223
1445610714
1448406377
1448603883
1449012307
1465203878
1465210998
1466410914

 

@George_Jokha See attached file.

I added a group counter in column K. Note K36 telling that that group number is not in use (zero times correct since A45 has 01312 in column B and thus belongs to group 10 on row 11).

ie, make sure that the logic is the way you want it to be.

-/-

I have extended the formula in c2 to use from a2 and end downwards, like Ctrl+Shift+Down Arrow.

endDown(a2) may be changed to A397 but will then not follow dynamically. And same for endDown(B2).

bosinander_1-1645519946013.png

 

 

=LET(prod1;A2:endDown(A2);
     prod2;B2:endDown(B2);
match1;    XLOOKUP(prod1;I3#;OFFSET(I3#;0;1));
match2;    XLOOKUP(prod2;I3#;OFFSET(I3#;0;1));
output;    IF(match2<match1;match2;match1);
output
)

 

endDown is a workbook local function built with the function LAMBDA. If you copy a cell using such function and paste it in another workbook, it will follow and be functional but as of 2022, only with 365.

The (long) formula for endDown is located in the name manager (Ctrl+F3).

Thank you very much! It realy helps! Great!

@George_Jokha You're welcome :):)

1 best response

Accepted Solutions
best response confirmed by George_Jokha (Copper Contributor)
Solution

@George_Jokha 

 

When you click "reply" you have a link to the left above the Post button where you can open full text editor.

bosinander_0-1645514534444.png

Well there you can attach the file just above the Post Button.

Make sure there is no names or secret data in it and I will take a look.

 

View solution in original post