I have two columns with team names and two columns with corresponding stats. I need to go through the 2 columns and find the stats that match the team name, and they need to be in order. VLOOKUP, MATCH, and SEARCH don't seem to work with multiple columns. Does anyone know how this can be done?
1 Answer
Assuming in your picture, the "Home" title is in cell B2 then the following array formula can be put in the cells H3:L7 (array formulas need to be entered with Ctrl+Shift+Enter)
=IFERROR(OFFSET($D$1,-1+SMALL(IF(($B$3:$B$7=H$2)+($C$3:$C$7=H$2),ROW($B$3:$B$7),"X"),ROW()-ROW($2:$2)),--NOT((INDEX($B:$B,SMALL(IF(($B$3:$B$7=H$2)+($C$3:$C$7=H$2),ROW($B$3:$B$7),"X"),ROW()-ROW($2:$2)))=H$2))),"")
Let me break it down...
- the logic is:
OFFSET(top_of_results,row_number_that_has_Nth_team_score,0_or_1_for_home_or_away) - this is wrapped in an
IFERRORin for where there isn't e.g. a 5th score for team A - using the array part
IF(($B$3:$B$7=H$2)+($C$3:$C$7=H$2),ROW($B$3:$B$7),"X"we get an array of that has theROWnumber if either (done using+)BorChave a value matching our team header (H$2) or anXotherwise - using
SMALL(...,ROW()-ROW($2:$2))we get the Nth smallest row, based on 1st being in row 3, 2nd in row 4 etc. - to get whether it is home or away, we check column B on our row to see if it matches
--NOT((INDEX($B:$B,row_number_that_has_Nth_team_score-O)=H$2))this gives 0 for home, 1 for away and this is used to offset the column
Hopefully it makes sense. Array formulas are very powerful, if a little confusing :-) I recommend CPearson's intro for more information.
Good luck!
1 Comment
Captain
@adam12344 Did this work for you? Feel free to accept the answer!
X - HomeandX-Viscolumns?