Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Index match unique values with multiple criteria?

I have the following list of users on 1 sheet, along with their age and sports interest:

A       18        Football
B       19        Rugby
C       18        Football
D       50        Dance
D       21        Rugby
A       25        Football

I then have an index match array formula on sheet 2 which is looking up my list of users and outputting them on sheet 1.

Formula:

 =IFERROR(INDEX('Activity Data'!$A$2:$A$5000, MATCH(0, COUNTIF($B$36:B36,'Activity Data'!$A$2:$A$5000), 0)),"")

This gives me a unique list of users like so:

A
B
C
D

However, i only want to look up those users who are 18 years old and who are interested in football.

How can i add multiple match criteria to this formula in order to get the desired result?

Thanks in advance

like image 567
mark_crown Avatar asked Nov 08 '22 17:11

mark_crown


1 Answers

If you do want to persevere with a formula, you can force a '1' when the criteria are not fulfilled as follows:-

=IFERROR(INDEX('Activity Data'!$A$2:$A$10, MATCH(0, SIGN(COUNTIF($C$36:C36,'Activity Data'!$A$2:$A$10)+('Activity Data'!$C$2:$C$10<>"Football")+('Activity Data'!$B$2:$B$10<>18)), 0)),"")

(I am only testing it on 10 rows but should work for any range)

Actually realised SIGN isn't necessary because anything not equal to zero won't be matched so:-

=IFERROR(INDEX('Activity Data'!$A$2:$A$10, MATCH(0, COUNTIF($C$36:C36,'Activity Data'!$A$2:$A$10)+('Activity Data'!$C$2:$C$10<>"Football")+('Activity Data'!$B$2:$B$10<>18), 0)),"")

enter image description here

But you may prefer to invert the logic and solve it in the more normal way like this:-

=IFERROR(INDEX('Activity Data'!$A$2:$A$10, MATCH(1, (COUNTIF($C$36:C36,'Activity Data'!$A$2:$A$10)=0)*('Activity Data'!$C$2:$C$10="Football")*('Activity Data'!$B$2:$B$10=18), 0)),"")

These are array formulae and must be entered using CtrlShiftEnter

like image 191
Tom Sharpe Avatar answered Dec 09 '22 04:12

Tom Sharpe