How to Search for and return the last 12 matches of a value in either of two columns of a table in one worksheet and return those rows in a second wor

widgewilliams

New Member
Joined
Apr 11, 2017
Messages
16
@widgewilliams

This thread is old and getting very big - difficult to locate the formula you are referring to and the corresponding data.

I suggest you create a new thread by showing us a small sample of your data along with expected results.

To post a sample of your data see section B in
https://www.mrexcel.com/forum/board-announcements/127080-guidelines-forum-use.html

Then, if you wish, you can put a link here to the new thread.

M.

As requested I've started a new post for this question.

In one worksheet "Historical Data" I have a table A1:BV1825. The data in that table is 5 years worth or English Premier League Results and is constantly being added to. Columns B through J are the ones of interest for this question.

BCDEFGHIJ
2DateHomeTeamAwayTeamFTHGFTAGFTRHTHGHTAGHTR
318/08/12ArsenalSunderland00D00D
418/08/12FulhamNorwich50H20H
518/08/12NewcastleTottenham21H00D
618/08/12QPRSwansea05A01A
718/08/12ReadingStoke11D01A
818/08/12West BromLiverpool30H10H
918/08/12West HamAston Villa10H10H
1019/08/12Man CitySouthampton32H10H

<tbody>
</tbody>


Each week new rows are added to the bottom of the table as the football seasons progress. Currently the last row is 1825.

18255/4/2017SwanseaTottenham13A10H

<tbody>
</tbody>

In a seperate worksheet "Output" I have a Drop Down List containing the names of each team in the English Premiership.

By selecting any particular team in the drop down list I am looking to pull a range of statistics for that team and display them in the Output worksheet.

One of those sets of statistics is the Current Form of the team over their last 12 games - both home and away.

What I (think) I need to be able to do is to look up columns C and D in the "Historical Data" worksheet to find matches to the drop down box Output!$B$2 and return the last 12 rows where there is a match to get both the Home and Away Form for the particular team I'm interested in and create a new table in the Output worksheet for those last 12 games with the following headings

DateHome TeamAway TeamHalf Time ScoreFull Time Score

<tbody>
</tbody>


I know that the following formula would find and display what I am after...

{=IFERROR(INDEX('Historical Data'!B$2:B$9999,SMALL(IF((('Historical Data'!$C$2:$C$9999=Output!$B$2)+('Historical Data'!$D$2:$D$9999=Output!$B$2)),ROW('Historical Data'!B$2:B$9999)-ROW('Historical Data'!B$2)+1),ROWS('Historical Data'!B$2:'Historical Data'!B2))),"")}

However, it will find and match working from row 1 downwards and so extract the oldest data first as shown below (with West Brom being the search value in this instance)

DateHome TeamAway TeamHalf TimeFull Time
18/08/12West BromLiverpool10H30H
25/08/12TottenhamWest Brom00D11D
1/9/2012West BromEverton00D20H
15/09/12FulhamWest Brom20H30H
22/09/12West BromReading00D10H
30/09/12Aston VillaWest Brom00D11D
6/10/2012West BromQPR21H32H
20/10/12West BromMan City00D12A
28/10/12NewcastleWest Brom10H21H
5/11/2012West BromSouthampton10H20H
10/11/2012WiganWest Brom12A12A
17/11/12West BromChelsea11D21H

<colgroup><col style="mso-width-source:userset;mso-width-alt:2340;width:48pt" width="64"> <col style="mso-width-source:userset;mso-width-alt:1755;width:36pt" width="48"> <col style="mso-width-source:userset;mso-width-alt:1536;width:32pt" width="42"> <col style="mso-width-source:userset;mso-width-alt:1462; width:30pt" span="11" width="40"> </colgroup><tbody>
</tbody>


What I am needing to do is start from the most recent matches which are to be found at the bottom of the historic data table and work backwards.

Can it be done, and how could I do it?

Thanks
 

Excel Facts

Select all contiguous cells
Pressing Ctrl+* (asterisk) will select the "current region" - all contiguous cells in all directions.
Try putting LARGE instead of SMALL in that formula.

Well, that was remarkably simple....

DateHome TeamAway TeamHalf TimeFull Time
4/4/2017WatfordWest Brom10H20H
4/1/2017Man UnitedWest Brom00D00D
3/18/2017West BromArsenal11D31H
3/11/2017EvertonWest Brom20H30H
3/4/2017West BromCrystal Palace00D02A
2/25/2017West BromBournemouth21H21H
2/11/2017West HamWest Brom01A22D
2/4/2017West BromStoke10H10H
1/31/2017MiddlesbroughWest Brom11D11D
1/21/2017West BromSunderland20H20H
1/14/2017TottenhamWest Brom20H40H
1/2/2017West BromHull01A31H

<colgroup><col style="mso-width-source:userset;mso-width-alt:2340;width:48pt" width="64"> <col style="mso-width-source:userset;mso-width-alt:1755;width:36pt" width="48"> <col style="mso-width-source:userset;mso-width-alt:1536;width:32pt" width="42"> <col style="mso-width-source:userset;mso-width-alt:1462; width:30pt" span="11" width="40"> </colgroup><tbody>
</tbody>

A bit of cut and pasting to rearrange the order...

DateHome TeamAway TeamHalf TimeFull Time
1/2/2017West BromHull01A31H
1/14/2017TottenhamWest Brom20H40H
1/21/2017West BromSunderland20H20H
1/31/2017MiddlesbroughWest Brom11D11D
2/4/2017West BromStoke10H10H
2/11/2017West HamWest Brom01A22D
2/25/2017West BromBournemouth21H21H
3/4/2017West BromCrystal Palace00D02A
3/11/2017EvertonWest Brom20H30H
3/18/2017West BromArsenal11D31H
4/1/2017Man UnitedWest Brom00D00D
4/4/2017WatfordWest Brom10H20H

<colgroup><col style="mso-width-source:userset;mso-width-alt:2340;width:48pt" width="64"> <col style="mso-width-source:userset;mso-width-alt:1755;width:36pt" width="48"> <col style="mso-width-source:userset;mso-width-alt:1536;width:32pt" width="42"> <col style="mso-width-source:userset;mso-width-alt:1462; width:30pt" span="11" width="40"> </colgroup><tbody>
</tbody>

And it is exactly what I was wanting to achieve. Clearly i need to understand what the Large and Small functions actually do.

Thank you so much Eric.
 
Upvote 0
Don't be confused my my setup here - I used your 'output' data as my source data. I extracted the most recent game into Row 18, the second most recent into Row 19 and onwards. I used an expanding range as part of the function AGGREGATE, whose function_num is 14 for LARGE. Copy B18 rightways. Then Copy Row 18 downwards for as many games as you want to extract (up to the number of games the team played in the master list (12 in my case).

ABCDEFGHI
1DateHome TeamAway TeamHalf TimeFull Time
28/18/2012West BromLiverpool10H30H
38/25/2012TottenhamWest Brom00D11D
49/1/2012West BromEverton00D20H
59/15/2012FulhamWest Brom20H30H
69/22/2012West BromReading00D10H
79/30/2012Aston VillaWest Brom00D11D
810/6/2012West BromQPR21H32H
910/20/2012West BromMan City00D12A
1010/28/2012NewcastleWest Brom10H21H
1111/5/2012West BromSouthampton10H20H
1211/10/2012WiganWest Brom12A12A
1311/17/2012West BromChelsea11D21H
14
15Lookup:West Brom
16
17DateHome TeamAway TeamHalf Time ScoreFull Time Score
1811/17/2012West BromChelsea11D21H
1911/10/2012WiganWest Brom12A12A
2011/5/2012West BromSouthampton10H20H
21et cetera

<tbody>
</tbody>
Sheet58

Worksheet Formulas
CellFormula
A18=AGGREGATE(14,6,($B$15=$B$2:$C$13)*$A$2:$A$13,ROWS($A$18:A18))
B18=INDEX(B$2:B$13,MATCH($A18,$A$2:$A$13))

<tbody>
</tbody>

<tbody>
</tbody>
 
Last edited:
Upvote 0
To avoid the cutting and pasting, you could do this:

{=IFERROR(INDEX('Historical Data'!B$2:B$9999,LARGE(IF((('Historical Data'!$C$2:$C$9999=Output!$B$2)+('Historical Data'!$D$2:$D$9999=Output!$B$2)),ROW('Historical Data'!B$2:B$9999)-ROW('Historical Data'!B$2)+1),13-ROWS('Historical Data'!B$2:'Historical Data'!B2))),"")}

Glad we could help.
 
Upvote 0
To avoid the cutting and pasting, you could do this:

{=IFERROR(INDEX('Historical Data'!B$2:B$9999,LARGE(IF((('Historical Data'!$C$2:$C$9999=Output!$B$2)+('Historical Data'!$D$2:$D$9999=Output!$B$2)),ROW('Historical Data'!B$2:B$9999)-ROW('Historical Data'!B$2)+1),13-ROWS('Historical Data'!B$2:'Historical Data'!B2))),"")}

Glad we could help.

That certainly does the trick Eric. Thanks again.

DRSteele said:
Eric certainly seems to have provided a solution to my question and fixed the need for cutting and pasting, but having taken the time to respond to me DRSteele it would only be right for me to take a look at your proposed solution also which, i suspect, would help me in some of the other things I am wanting to do.

I've have encountered a problem though in that I get the following results.

4/4/2017WatfordWest Brom10H20H
4/1/2017WatfordSunderland00D10H
3/18/2017West HamLeicester13A23A
3/11/2017HullSwansea00D21H
3/4/2017West BromCrystal Palace00D02A
2/25/2017West BromBournemouth21H21H
2/11/2017West HamWest Brom01A22D
2/4/2017West BromStoke10H10H
1/31/2017SwanseaSouthampton10H21H
1/21/2017West BromSunderland20H20H
1/14/2017West HamCrystal Palace00D30H
1/2/2017West HamMan United00D02A

<tbody>
</tbody>


I suspect that the reason is because my actual source data contains every game played in the EPL, and not just West Brom's.

Would I be right in thinking that A18 pulls the dates of West Broms last 12 games, and B12 then matches to that date? If so then what seems to be happening is that B12 is retrieving the last game in the source data for that particular date, as can be seen below.

3/11/2017BournemouthWest Ham32H11D
3/11/2017EvertonWest Brom30H20H
3/11/2017
HullSwansea21H00D
3/12/2017LiverpoolBurnley21H11D
3/18/2017BournemouthSwansea20H10H
3/18/2017Crystal PalaceWatford10H00D
3/18/2017EvertonHull40H10H
3/18/2017StokeChelsea12A11D
3/18/2017SunderlandBurnley00D00D
3/18/2017West BromArsenal31H11D
3/18/2017
West HamLeicester23A13A
3/19/2017Man CityLiverpool11D00D
3/19/2017MiddlesbroughMan United13A01A
3/19/2017TottenhamSouthampton21H20H
4/1/2017BurnleyTottenham02A00D
4/1/2017ChelseaCrystal Palace12A12A
4/1/2017HullWest Ham21H01A
4/1/2017LeicesterStoke20H10H
4/1/2017LiverpoolEverton31H21H
4/1/2017Man UnitedWest Brom00D00D
4/1/2017SouthamptonBournemouth00D00D
4/1/2017
WatfordSunderland10H00D
4/2/2017ArsenalMan City22D12A
4/2/2017SwanseaMiddlesbrough00D00D
4/4/2017BurnleyStoke10H00D
4/4/2017LeicesterSunderland20H00D
4/4/2017Man UnitedEverton11D01A
4/4/2017
WatfordWest Brom20H10H
5/4/2017ArsenalWest Ham30H00D
5/4/2017ChelseaMan City21H21H
5/4/2017HullMiddlesbrough42H32H
5/4/2017LiverpoolBournemouth22D11D
5/4/2017SouthamptonCrystal Palace31H11D
5/4/2017SwanseaTottenham13A10H

<tbody>
</tbody>
 
Upvote 0

Forum statistics

Threads
1,214,932
Messages
6,122,334
Members
449,077
Latest member
Jocksteriom

We've detected that you are using an adblocker.

We have a great community of people providing Excel help here, but the hosting costs are enormous. You can help keep this site running by allowing ads on MrExcel.com.
Allow Ads at MrExcel

Which adblocker are you using?

Disable AdBlock

Follow these easy steps to disable AdBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the icon in the browser’s toolbar.
2)Click on the "Pause on this site" option.
Go back

Disable AdBlock Plus

Follow these easy steps to disable AdBlock Plus

1)Click on the icon in the browser’s toolbar.
2)Click on the toggle to disable it for "mrexcel.com".
Go back

Disable uBlock Origin

Follow these easy steps to disable uBlock Origin

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back

Disable uBlock

Follow these easy steps to disable uBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back
Back
Top