Identify last 5 occurences in a list of multiple columns

PedroGomez9

New Member
Joined
Feb 25, 2021
Messages
6
Office Version
  1. 2016
Platform
  1. Windows
Hi guys

I have a list of sporting results, and I'm trying to put a TRUE/FALSE on whether or not it's one of the team's last 'x' (user-defined, changeable value) games - they can appear in either Column A or Column B.
I have a helper column, lets call it C1 for arguments sake with the user defined value of games I'm looking to isolate.

HomeTeamAwayTeam
WatfordMiddlesbrough
FulhamArsenal
BirminghamBrentford
WycombeRotherham
Crystal PalaceSouthampton
BarnsleyLuton
BournemouthBlackburn
Bristol CityCoventry
CardiffSheffield Weds
DerbyReading
HuddersfieldNorwich
MillwallStoke
PrestonSwansea
QPRNott'm Forest
AccringtonPeterboro
CreweCharlton
DoncasterMilton Keynes Dons
Fleetwood TownBurton
GillinghamHull
LincolnOxford
NorthamptonAFC Wimbledon
PlymouthBlackpool
PortsmouthShrewsbury
SunderlandBristol Rvs
SwindonRochdale
BarrowStevenage
BoltonForest Green
BradfordColchester
CambridgeCarlisle
CheltenhamMorecambe
MansfieldTranmere
OldhamLeyton Orient
Port ValeCrawley Town
SalfordExeter
ScunthorpeNewport County
SouthendHarrogate
WalsallGrimsby
LiverpoolLeeds
West HamNewcastle
IpswichWigan
West BromLeicester
TottenhamEverton
Sheffield UnitedWolves
BrightonChelsea
CoventryQPR
EvertonWest Brom
Nott'm ForestCardiff
CarlisleSouthend
LeedsFulham
BlackburnWycombe
BrentfordHuddersfield
LutonDerby
MiddlesbroughBournemouth
NorwichPreston
ReadingBarnsley
RotherhamMillwall
Sheffield WedsWatford
SwanseaBirmingham
AFC WimbledonPlymouth
BlackpoolSwindon
Bristol RvsIpswich
BurtonAccrington
CharltonDoncaster
HullCrewe
Milton Keynes DonsLincoln
OxfordSunderland
PeterboroFleetwood Town
ShrewsburyNorthampton
WiganGillingham
ColchesterBolton
Crawley TownScunthorpe
ExeterPort Vale
Forest GreenBradford
GrimsbySalford
HarrogateWalsall
Leyton OrientMansfield
MorecambeCambridge
Newport CountyBarrow
StevenageOldham
TranmereCheltenham
Man UnitedCrystal Palace
ArsenalWest Ham
SouthamptonTottenham
NewcastleBrighton
StokeBristol City
RochdalePortsmouth
ChelseaLiverpool
LeicesterBurnley
Aston VillaSheffield United
WolvesMan City
HuddersfieldNott'm Forest
BrightonMan United
WatfordLuton
WycombeSwansea
Crystal PalaceEverton
BarnsleyCoventry
BirminghamRotherham
CardiffReading
DerbyBlackburn
 

Excel Facts

Best way to learn Power Query?
Read M is for (Data) Monkey book by Ken Puls and Miguel Escobar. It is the complete guide to Power Query.
Something like this?

21 03 30.xlsm
ABCDEF
1HomeTeamAwayTeamLast n?TeamSwansea
2WatfordMiddlesbrough Last N2
3FulhamArsenal 
4BirminghamBrentford 
5WycombeRotherham 
6Crystal PalaceSouthampton 
7BarnsleyLuton 
8BournemouthBlackburn 
9Bristol CityCoventry 
10CardiffSheffield Weds 
11DerbyReading 
12HuddersfieldNorwich 
13MillwallStoke 
14PrestonSwanseaFALSE
15QPRNott'm Forest 
16AccringtonPeterboro 
17CreweCharlton 
18DoncasterMilton Keynes Dons 
19Fleetwood TownBurton 
20GillinghamHull 
21LincolnOxford 
22NorthamptonAFC Wimbledon 
23PlymouthBlackpool 
24PortsmouthShrewsbury 
25SunderlandBristol Rvs 
26SwindonRochdale 
27BarrowStevenage 
28BoltonForest Green 
29BradfordColchester 
30CambridgeCarlisle 
31CheltenhamMorecambe 
32MansfieldTranmere 
33OldhamLeyton Orient 
34Port ValeCrawley Town 
35SalfordExeter 
36ScunthorpeNewport County 
37SouthendHarrogate 
38WalsallGrimsby 
39LiverpoolLeeds 
40West HamNewcastle 
41IpswichWigan 
42West BromLeicester 
43TottenhamEverton 
44Sheffield UnitedWolves 
45BrightonChelsea 
46CoventryQPR 
47EvertonWest Brom 
48Nott'm ForestCardiff 
49CarlisleSouthend 
50LeedsFulham 
51BlackburnWycombe 
52BrentfordHuddersfield 
53LutonDerby 
54MiddlesbroughBournemouth 
55NorwichPreston 
56ReadingBarnsley 
57RotherhamMillwall 
58Sheffield WedsWatford 
59SwanseaBirminghamTRUE
60AFC WimbledonPlymouth 
61BlackpoolSwindon 
62Bristol RvsIpswich 
63BurtonAccrington 
64CharltonDoncaster 
65HullCrewe 
66Milton Keynes DonsLincoln 
67OxfordSunderland 
68PeterboroFleetwood Town 
69ShrewsburyNorthampton 
70WiganGillingham 
71ColchesterBolton 
72Crawley TownScunthorpe 
73ExeterPort Vale 
74Forest GreenBradford 
75GrimsbySalford 
76HarrogateWalsall 
77Leyton OrientMansfield 
78MorecambeCambridge 
79Newport CountyBarrow 
80StevenageOldham 
81TranmereCheltenham 
82Man UnitedCrystal Palace 
83ArsenalWest Ham 
84SouthamptonTottenham 
85NewcastleBrighton 
86StokeBristol City 
87RochdalePortsmouth 
88ChelseaLiverpool 
89LeicesterBurnley 
90Aston VillaSheffield United 
91WolvesMan City 
92HuddersfieldNott'm Forest 
93BrightonMan United 
94WatfordLuton 
95WycombeSwanseaTRUE
96Crystal PalaceEverton 
97BarnsleyCoventry 
98BirminghamRotherham 
99CardiffReading 
100DerbyBlackburn 
Last n
Cell Formulas
RangeFormula
C2:C100C2=IF(COUNTIF(A2:B2,F$1),COUNTIF(C3:C$1000,TRUE)<F$2,"")
 
Upvote 0
Hi Peter

Thanks for the reply. It's close to what I'm after, but ideally for all rows instead of being team specific.

For example I already have it broken down whether or not it's within each team's last 'n' home games OR their last 5 away games... I just can't figure out how to get it so that it's their last 5 games irrespective of home or away.

A more comprehensive data set is below (Columns A-N, with column N ideally housing the TRUE/FALSE).
Formula already used to calculate if it's the last 'n' in either column is:

=COUNTIF(C1:C$1938,[@HomeTeam])<='User Defined Analysis'!$B$1

This is dragged down to all subsequent cells, whereby 'User Defined Analysis'!$B$1 is my 'n' value.

DivDateHomeTeamAwayTeamHomeTeamGoalsAwayTeamGoalsResultTotalGoalsBTTSHomeTeamYellowAwayTeamYellowIs last 'x' home?Is last 'x' away?Last 'x' overall
FL116/02/2021IpswichNorthampton00D0No23TRUETRUE
FL216/02/2021BradfordMorecambe21H3Yes13TRUETRUE
FL216/02/2021Crawley TownStevenage01A1No36FALSETRUE
FL216/02/2021Forest GreenOldham43H7Yes23TRUEFALSE
FL216/02/2021HarrogateCarlisle10H1No11TRUEFALSE
FL216/02/2021Newport CountyExeter11D2Yes00TRUEFALSE
FL216/02/2021SalfordBarrow10H1No22TRUETRUE
FL216/02/2021WalsallCheltenham12A3Yes20TRUETRUE
CONF16/02/2021AldershotSolihull13A4Yes30TRUEFALSE
CONF16/02/2021BarnetHalifax21H3Yes21TRUETRUE
CONF16/02/2021Dag and RedBromley10H1No21FALSETRUE
CONF16/02/2021WrexhamWoking20H2No03TRUEFALSE
FLC16/02/2021Bristol CityReading02A2No43TRUETRUE
FLC16/02/2021MiddlesbroughHuddersfield21H3Yes11TRUETRUE
FLC16/02/2021WycombeDerby12A3Yes22FALSEFALSE
CONF16/02/2021Boreham WoodYeovil23A5Yes36TRUEFALSE
CONF16/02/2021King’s LynnNotts County01A1No42TRUETRUE
CONF16/02/2021MaidenheadStockport00D0No32TRUETRUE
FLC16/02/2021LutonCardiff02A2No01TRUETRUE
FL217/02/2021MansfieldBolton23A5Yes20FALSETRUE
FL117/02/2021WiganHull05A5No10TRUETRUE
EPL17/02/2021BurnleyFulham11D2Yes11TRUETRUE
FLC17/02/2021CoventryNorwich02A2No13TRUEFALSE
FLC17/02/2021MillwallBirmingham20H2No22TRUETRUE
FLC17/02/2021QPRBrentford21H3Yes51FALSETRUE
FLC17/02/2021SwanseaNott'm Forest10H1No10TRUETRUE
FL117/02/2021DoncasterAccrington01A1No01TRUETRUE
FLC17/02/2021BarnsleyBlackburn21H3Yes11FALSETRUE
 
Upvote 0
  1. What would that final column mean if True for one team and false for the other?
  2. Do you really want the two columns you already have or prefer to go straight to that final column if possible?
  3. Is this data in a formal Excel table (your use of [@Home Team])?
 
Upvote 0
1. True/False columns 1 & 2 don't really have any bearing on the outcome of column 3. Column 1 is if the row is one of the team's last 5 home games, and column 2 is if it's one of the team's last 5 away games. Column 3 should ideally isolate the last 5 games irrespective of home or away.
2. As above, they are separate calculations so would need to stay.
3. Yes it's in a formal Excel table
 
Upvote 0
how to get it so that it's their last 5 games irrespective of home or away.
Who is their?
You seem to be describing something that will be returned in a single column. However, there are two teams on each row.
What would you want returned in that single column if for team 'A' it is one of their last 'x' games but for team 'B' on the same row it is not one of their last 'x' games?

Perhaps you could clarify by copying this to a blank worksheet, manually completing the final column and posting it back here with any further explanation.

BTW, I have suggested alternative formulas for the original two columns of results. They are a little longer that what you are currently using but do lend themselves more fully to the table structure/nomenclature. Do they give the results you want?

PedroGomez9.xlsm
CDLMNOPQ
1HomeTeamAwayTeamIs last 'x' home?Is last 'x' away?Last 'x' overallLast x ->3
2BAFALSEFALSE
3BDFALSEFALSE
4BCFALSEFALSE
5ECFALSEFALSE
6CAFALSEFALSE
7DAFALSEFALSE
8AEFALSETRUE
9BATRUETRUE
10ABFALSEFALSE
11ECTRUEFALSE
12AEFALSETRUE
13BDTRUEFALSE
14DBFALSEFALSE
15CBFALSEFALSE
16ADFALSETRUE
17CBTRUETRUE
18ABFALSETRUE
19EDTRUETRUE
20DCTRUEFALSE
21CBTRUETRUE
22ACTRUEFALSE
23DATRUETRUE
24BETRUETRUE
25EDTRUETRUE
26CATRUETRUE
27DCTRUETRUE
28ACTRUETRUE
29ACTRUETRUE
Last n
Cell Formulas
RangeFormula
L2:L29L2=COUNTIF([@HomeTeam]:INDEX([HomeTeam],ROWS([HomeTeam])),[@HomeTeam])<=$Q$1
M2:M29M2=COUNTIF([@AwayTeam]:INDEX([AwayTeam],ROWS([AwayTeam])),[@AwayTeam])<=$Q$1
 
Upvote 0

Forum statistics

Threads
1,214,908
Messages
6,122,187
Members
449,072
Latest member
DW Draft

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