Home > other >  Google Sheets - finding first match in array formula
Google Sheets - finding first match in array formula

Time:11-24

Okay, I found many solution for many problems in Google Sheets, but this one is just hard as a rock. :)

I have a sheet where in column C are various names and in column D are professions. For example:

C / D
John Smith / plumber
Paul Anderson / carpenter
Sarah Palmer / dentist
Jonah Huston / carpenter
Laura Jones / dentist
Sid Field / carpenter
...etc

(as you can see every name are identical, but professions are repeating several times)

I'd like to see in column F the last matching name of the same profession

C / D / F
John Smith / plumber / (N/A)
Paul Anderson / carpenter /Jonah Huston
Sarah Palmer / dentist / Laura Jones
Jonah Huston / carpenter / Sid Field
Laura Jones / dentist / (N/A)
Sid Field / carpenter / (N/A)
...etc

It works fine with INDEX and FILTER function, but I have to copy the code over and over again as I add extra rows. This is the code I use:

=IFERROR(INDEX(FILTER($C4:$C,$D4:$D=D6,$A4:$A<A6),1))

I'm looking for a solution with Array Formula to autofill all cells in column F, and tried various versions (Lookup, Vlookup..etc), but couldn't find the right formula.

Any guidance would be appreciated. :)

CodePudding user response:

try:

=INDEX(IF(C1:C="",,IFNA(VLOOKUP(
 D1:D&COUNTIFS(D1:D, D1:D, ROW(D1:D), "<="&ROW(D1:D)), {
 D1:D&COUNTIFS(D1:D, D1:D, ROW(D1:D), "<="&ROW(D1:D))-1, 
 C1:C}, 2, 0), "(N/A)")))

enter image description here

  • Related