SOLVED

Find Common Values In ALL 5 Columns With Array Formulas

%3CLINGO-SUB%20id%3D%22lingo-sub-2316305%22%20slang%3D%22en-US%22%3EFind%20Common%20Values%20In%20ALL%205%20Columns%20With%20Array%20Formulas%3C%2FLINGO-SUB%3E%3CLINGO-BODY%20id%3D%22lingo-body-2316305%22%20slang%3D%22en-US%22%3E%3CP%3EHello%2C%26nbsp%3B%3C%2FP%3E%3CP%3EI%20have%20test%20data%20of%20101%20rows%20containing%203%20or%204%20Alphabet%20symbols%20in%205%20columns.%20Some%20of%20these%203%20or%204%20letter%20symbols%20can%20be%20found%20across%20all%205%20columns%20though%20not%20in%20the%20same%20row%20e.g.%20%22BDRY%22%20can%20be%20found%20in%20all%20columns%20but%20in%20different%20rows%20when%20eyeballing%20each%20column.%20My%20intent%20is%20to%20programmatically%20find%20all%20such%20values%20across%20all%205%20columns%20because%20the%20values%20in%20each%20of%20the%20cells%20can%20change.%20Also%20note%2C%20all%205%20columns%20have%20been%20sorted%20A-Z%20individually.%3C%2FP%3E%3CP%3E%26nbsp%3B%3C%2FP%3E%3CP%3EI%20think%20I%20have%20got%20close%20with%20this%20formula%20but%20cannot%20figure%20out%20the%20%26gt%3B0%2C1%2C0%20or%20%3D2%2C0%2C1%20which%20are%20arrays%20for%203%20columns%20which%20is%20perhaps%20why%20I%20am%20getting%20an%20error%20(0%20value%20across%20all%20values%20).%3C%2FP%3E%3CP%3E%26nbsp%3B%3C%2FP%3E%3CP%3EMy%20intention%20is%20to%20compared%20all%205%20columns.%20Can%20someone%20please%20correct%20this%20formula%3F%20Test%20file%20(Test_data.xls)%20attached)%26nbsp%3B%3C%2FP%3E%3CP%3E%26nbsp%3B%3C%2FP%3E%3CP%3E%3DINDEX(%24A%242%3A%24A%24101%2CMATCH(0%2CCOUNTIF(%24F%242%3AF2%2C%24A%242%3A%24A%24101)%2BIF(IF(COUNTIF(%24B%242%3A%24B%24101%2C%24A%242%3A%24A%24101)%26gt%3B0%2C1%2C0)%2BIF(COUNTIF(%24C%242%3A%24C%24101%2C%24A%242%3A%24A%24101)%26gt%3B0%2C1%2C0)%2BIF(COUNTIF(%24D%242%3A%24D%24101%2C%24A%242%3A%24A%24101)%26gt%3B0%2C1%2C0)%2BIF(COUNTIF(%24E%242%3A%24E%24101%2C%24A%242%3A%24A%24101)%26gt%3B0%2C1%2C0)%3D2%2C0%2C1)%2C0))%3C%2FP%3E%3CP%3E%26nbsp%3B%3C%2FP%3E%3CP%3ERegards%2C%3C%2FP%3E%3CP%3EAmlesh%3C%2FP%3E%3C%2FLINGO-BODY%3E%3CLINGO-LABS%20id%3D%22lingo-labs-2316305%22%20slang%3D%22en-US%22%3E%3CLINGO-LABEL%3EExcel%3C%2FLINGO-LABEL%3E%3CLINGO-LABEL%3EFormulas%20and%20Functions%3C%2FLINGO-LABEL%3E%3C%2FLINGO-LABS%3E%3CLINGO-SUB%20id%3D%22lingo-sub-2317021%22%20slang%3D%22en-US%22%3ERe%3A%20Find%20Common%20Values%20In%20ALL%205%20Columns%20With%20Array%20Formulas%3C%2FLINGO-SUB%3E%3CLINGO-BODY%20id%3D%22lingo-body-2317021%22%20slang%3D%22en-US%22%3E%3CP%3E%3CA%20href%3D%22https%3A%2F%2Ftechcommunity.microsoft.com%2Ft5%2Fuser%2Fviewprofilepage%2Fuser-id%2F1043406%22%20target%3D%22_blank%22%3E%40Amlesh7400%3C%2FA%3E%26nbsp%3BPerhaps%20easiest%20with%20Power%20Query.%20In%20the%20attached%20workbook%20you'll%20find%20a%20sheet%20called%20%22Count%22.%20I%20trust%20you%20can%20do%20your%20analysis%20from%20there.%3C%2FP%3E%3C%2FLINGO-BODY%3E%3CLINGO-SUB%20id%3D%22lingo-sub-2324537%22%20slang%3D%22en-US%22%3ERe%3A%20Find%20Common%20Values%20In%20ALL%205%20Columns%20With%20Array%20Formulas%3C%2FLINGO-SUB%3E%3CLINGO-BODY%20id%3D%22lingo-body-2324537%22%20slang%3D%22en-US%22%3E%3CA%20href%3D%22https%3A%2F%2Ftechcommunity.microsoft.com%2Ft5%2Fuser%2Fviewprofilepage%2Fuser-id%2F403176%22%20target%3D%22_blank%22%3E%40Riny_van_Eekelen%3C%2FA%3E%20Thank%20you%20very%20much.%20if%20possible%2C%20can%20you%20share%20the%20Power%20Query%20so%20i%20can%20output%20a%20new%20excel%20file%20anytime%20the%20cell%20values%20change%3F%3CBR%20%2F%3ERegards%2C%3CBR%20%2F%3E%3C%2FLINGO-BODY%3E%3CLINGO-SUB%20id%3D%22lingo-sub-2324659%22%20slang%3D%22en-US%22%3ERe%3A%20Find%20Common%20Values%20In%20ALL%205%20Columns%20With%20Array%20Formulas%3C%2FLINGO-SUB%3E%3CLINGO-BODY%20id%3D%22lingo-body-2324659%22%20slang%3D%22en-US%22%3E%3CP%3E%3CA%20href%3D%22https%3A%2F%2Ftechcommunity.microsoft.com%2Ft5%2Fuser%2Fviewprofilepage%2Fuser-id%2F1043406%22%20target%3D%22_blank%22%3E%40Amlesh7400%3C%2FA%3E%26nbsp%3BWell%2C%20the%20query%20that%20generates%20the%20table%20is%20in%20the%20file%20that%20is%20attached%20to%20my%20previous%20post.%20Depending%20on%20your%20Excel%20version%20you%20may%20have%20a%20separate%20Power%20Query%20tab%2Fribbon%20or%20you'll%20find%20the%20tools%20needed%20on%20the%20Data%20ribbon%20under%20%22Get%20%26amp%3B%20Transform%20Data%22.%3C%2FP%3E%3CP%3EThe%20steps%20applied%20to%20achieve%20the%20output%20aren't%20very%20complicated%2C%20that%20is%2C%20if%20you%20are%20familiar%20with%20Power%20Query.%20Otherwise%20you%20may%20get%20lost%20in%20all%20the%20options%20and%20icons.%3C%2FP%3E%3CP%3E%26nbsp%3B%3C%2FP%3E%3C%2FLINGO-BODY%3E%3CLINGO-SUB%20id%3D%22lingo-sub-2324737%22%20slang%3D%22en-US%22%3ERe%3A%20Find%20Common%20Values%20In%20ALL%205%20Columns%20With%20Array%20Formulas%3C%2FLINGO-SUB%3E%3CLINGO-BODY%20id%3D%22lingo-body-2324737%22%20slang%3D%22en-US%22%3E%3CP%3E%3CA%20href%3D%22https%3A%2F%2Ftechcommunity.microsoft.com%2Ft5%2Fuser%2Fviewprofilepage%2Fuser-id%2F403176%22%20target%3D%22_blank%22%3E%40Riny_van_Eekelen%3C%2FA%3E%26nbsp%3B%3C%2FP%3E%3CP%3E%26nbsp%3B%3C%2FP%3E%3CP%3EI%20have%20got%20the%20latest%20version%20of%20Excel%20for%20365%20subscription%20but%20don't%20know%20much%20about%20Power%20Query%20so%20thanks%20for%20the%20tip%20to%20help%20explore%20to%20refine%20my%20skills.%3C%2FP%3E%3CP%3Ebtw%20I%20stumbled%20upon%20a%20simpler%20formula%20using%20conditional%20formatting%20%26gt%3B%20highlight%20cell%20rules%20%26gt%3B%20use%20a%20formula%20to%20determine%20which%20cells%20to%20format%3C%2FP%3E%3CP%3E%3DCOUNTIF(%24A%242%3A%24E%24101%2CA2)%26gt%3B4%3C%2FP%3E%3CP%3EOutput%20is%20highlighted%20in%20chosen%20cell%20colour.%3C%2FP%3E%3CP%3E%26nbsp%3B%3C%2FP%3E%3CP%3E%26nbsp%3B%3C%2FP%3E%3C%2FLINGO-BODY%3E
Occasional Contributor

Hello, 

I have test data of 101 rows containing 3 or 4 Alphabet symbols in 5 columns. Some of these 3 or 4 letter symbols can be found across all 5 columns though not in the same row e.g. "BDRY" can be found in all columns but in different rows when eyeballing each column. My intent is to programmatically find all such values across all 5 columns because the values in each of the cells can change. Also note, all 5 columns have been sorted A-Z individually.

 

I think I have got close with this formula but cannot figure out the >0,1,0 or =2,0,1 which are arrays for 3 columns which is perhaps why I am getting an error (0 value across all values ).

 

My intention is to compared all 5 columns. Can someone please correct this formula? Test file (Test_data.xls) attached) 

 

=INDEX($A$2:$A$101,MATCH(0,COUNTIF($F$2:F2,$A$2:$A$101)+IF(IF(COUNTIF($B$2:$B$101,$A$2:$A$101)>0,1,0)+IF(COUNTIF($C$2:$C$101,$A$2:$A$101)>0,1,0)+IF(COUNTIF($D$2:$D$101,$A$2:$A$101)>0,1,0)+IF(COUNTIF($E$2:$E$101,$A$2:$A$101)>0,1,0)=2,0,1),0))

 

Regards,

Amlesh

9 Replies
best response confirmed by Amlesh7400 (Occasional Contributor)
Solution

@Amlesh7400 Perhaps easiest with Power Query. In the attached workbook you'll find a sheet called "Count". I trust you can do your analysis from there.

@Riny_van_Eekelen Thank you very much. if possible, can you share the Power Query so i can output a new excel file anytime the cell values change?
Regards,

@Amlesh7400 Well, the query that generates the table is in the file that is attached to my previous post. Depending on your Excel version you may have a separate Power Query tab/ribbon or you'll find the tools needed on the Data ribbon under "Get & Transform Data".

The steps applied to achieve the output aren't very complicated, that is, if you are familiar with Power Query. Otherwise you may get lost in all the options and icons.

 

@Riny_van_Eekelen 

 

I have got the latest version of Excel for 365 subscription but don't know much about Power Query so thanks for the tip to help explore to refine my skills.

btw I stumbled upon a simpler formula using conditional formatting > highlight cell rules > use a formula to determine which cells to format

=COUNTIF($A$2:$E$101,A2)>4

Output is highlighted in chosen cell colour.

 

 

@Amlesh7400 To begin with PQ, the link below could be a good starting point.

https://exceloffthegrid.com/power-query-introduction/ 

 

As to your other question, I'm not sure what the problem is. The rule you mentioned, colours a cell if the value in A2 occurs more than 4 times in the range specified A2:E101. If that is not what you want, what is it?

it is exactly what i wanted and i solved it using a far simpler formula for me that is, without having to use power query.

@Amlesh7400 

Since you are using Excel 365, you could list the codes that appear in each column using

= LET(
   n, ROWS(Table1),
   k, SEQUENCE(5*n,,0),
   c, 1+MOD(k,5),
   r, 1+QUOTIENT(k,5),
   unpivoted, INDEX(Table1,r,c),
   distinct, SORT(UNIQUE(unpivoted)),
   FILTER(distinct, COUNTIFS(Table1,distinct)=5))

With Insider beta channel the unwieldly unpivoting step can be hidden within a Lambda function

= LAMBDA(tbl,
    LET(
       n, ROWS(Table1),
       k, SEQUENCE(5*n,,0),
       c, 1+MOD(k,5),
       r, 1+QUOTIENT(k,5),
       unpivotted, INDEX(Table1,r,c),
       SORT(UNIQUE(unpivotted)))
    )

to give

= LET(
   distinct, UNPIVOTλ(Table1),
   count, COUNTIFS(Table1, distinct),
   FILTER(distinct, count=5))

@Peter Bartholomew 

 

Thank You. My skills in Excel are limited to using basic formulas so would like to know whether I have to input this "policy" (looks like AWS type policy to me) in power query? or is the "LET" formula to be created?

@Amlesh7400 

The formulas are straightforward worksheet formulas (OK, perhaps not so straightforward).  The LET function, and now the LAMBDA function (available within the beta channel), are somewhat 'work in progress' that is building towards Excel as a full-blown software development platform!

I hope I have not created too much confusion; I realise that this is not what a typical Excel user expects to see!

 

Notes: the open and closed circles are conditional formats designed to highlight 'count=5'.

The small filtered table uses a Lambda function to 'hide' the calculation complexity.

 

image.png