Sumif but only last 6 occurrences

SHARPY1

Board Regular
Joined
Oct 1, 2007
Messages
183
I have this sumif function,
but this will sum about 50 occurrences of data in E329,
how do i adapt formula to just sumif last 6 occurrences??

=SUMIF(E2:E328,E329,I2:I328)

Any help appreciated
Cheers
 

Excel Facts

Links? Where??
If Excel says you have links but you can't find them, go to Formulas, Name Manager. Look for old links to dead workbooks & delete.
Hi everyone,

Sorry to resurrect a 3 year old post (seems that's been a theme on this post since it was created 13 years ago!!)

I'm trying to do something, a little more simple than some of the previous posters but using what I suspect is a similar data set - I just can't figure it out!!

There's around 1500 rows of data, with 115 different teams featuring in the list around 10-15 times each at home, and a similar amount away. All I need to do is isolate the last 5 times each team name appears in the home column, and then the same for the away column with a true or false statement. I'm trying to build a picture of 'form' so need to use only the most recent 5 instances of data listed.

Selection of data listed below.

Thanks in advance!

DivDateHomeTeamAwayTeamIs last 5 home?Is last 5 away?
FLC11/09/2020WatfordMiddlesbrough
EPL12/09/2020FulhamArsenal
FLC12/09/2020BirminghamBrentford
FLC12/09/2020WycombeRotherham
EPL12/09/2020Crystal PalaceSouthampton
FLC12/09/2020BarnsleyLuton
FLC12/09/2020BournemouthBlackburn
FLC12/09/2020Bristol CityCoventry
FLC12/09/2020CardiffSheffield Weds
FLC12/09/2020DerbyReading
FLC12/09/2020HuddersfieldNorwich
FLC12/09/2020MillwallStoke
FLC12/09/2020PrestonSwansea
FLC12/09/2020QPRNott'm Forest
FL112/09/2020AccringtonPeterboro
FL112/09/2020CreweCharlton
FL112/09/2020DoncasterMilton Keynes Dons
FL112/09/2020Fleetwood TownBurton
FL112/09/2020GillinghamHull
FL112/09/2020LincolnOxford
FL112/09/2020NorthamptonAFC Wimbledon
FL112/09/2020PlymouthBlackpool
FL112/09/2020PortsmouthShrewsbury
FL112/09/2020SunderlandBristol Rvs
FL112/09/2020SwindonRochdale
FL212/09/2020BarrowStevenage
FL212/09/2020BoltonForest Green
FL212/09/2020BradfordColchester
FL212/09/2020CambridgeCarlisle
FL212/09/2020CheltenhamMorecambe
FL212/09/2020MansfieldTranmere
FL212/09/2020OldhamLeyton Orient
FL212/09/2020Port ValeCrawley Town
FL212/09/2020SalfordExeter
FL212/09/2020ScunthorpeNewport County
FL212/09/2020SouthendHarrogate
FL212/09/2020WalsallGrimsby
EPL12/09/2020LiverpoolLeeds
EPL12/09/2020West HamNewcastle
FL113/09/2020IpswichWigan
EPL13/09/2020West BromLeicester
EPL13/09/2020TottenhamEverton
EPL14/09/2020Sheffield UnitedWolves
EPL14/09/2020BrightonChelsea
FLC18/09/2020CoventryQPR
EPL19/09/2020EvertonWest Brom
FLC19/09/2020Nott'm ForestCardiff
FL219/09/2020CarlisleSouthend
EPL19/09/2020LeedsFulham
FLC19/09/2020BlackburnWycombe
FLC19/09/2020BrentfordHuddersfield
FLC19/09/2020LutonDerby
FLC19/09/2020MiddlesbroughBournemouth
FLC19/09/2020NorwichPreston
FLC19/09/2020ReadingBarnsley
FLC19/09/2020RotherhamMillwall
FLC19/09/2020Sheffield WedsWatford
FLC19/09/2020SwanseaBirmingham
FL119/09/2020AFC WimbledonPlymouth
FL119/09/2020BlackpoolSwindon
FL119/09/2020Bristol RvsIpswich
FL119/09/2020BurtonAccrington
FL119/09/2020CharltonDoncaster
FL119/09/2020HullCrewe
FL119/09/2020Milton Keynes DonsLincoln
FL119/09/2020OxfordSunderland
FL119/09/2020PeterboroFleetwood Town
FL119/09/2020ShrewsburyNorthampton
FL119/09/2020WiganGillingham
FL219/09/2020ColchesterBolton
FL219/09/2020Crawley TownScunthorpe
FL219/09/2020ExeterPort Vale
FL219/09/2020Forest GreenBradford
FL219/09/2020GrimsbySalford
FL219/09/2020HarrogateWalsall
FL219/09/2020Leyton OrientMansfield
FL219/09/2020MorecambeCambridge
FL219/09/2020Newport CountyBarrow
FL219/09/2020StevenageOldham
FL219/09/2020TranmereCheltenham
EPL19/09/2020Man UnitedCrystal Palace
EPL19/09/2020ArsenalWest Ham
EPL20/09/2020SouthamptonTottenham
EPL20/09/2020NewcastleBrighton
FLC20/09/2020StokeBristol City
FL120/09/2020RochdalePortsmouth
EPL20/09/2020ChelseaLiverpool
EPL20/09/2020LeicesterBurnley
EPL21/09/2020Aston VillaSheffield United
EPL21/09/2020WolvesMan City
FLC25/09/2020HuddersfieldNott'm Forest
EPL26/09/2020BrightonMan United
FLC26/09/2020WatfordLuton
FLC26/09/2020WycombeSwansea
EPL26/09/2020Crystal PalaceEverton
FLC26/09/2020BarnsleyCoventry
FLC26/09/2020BirminghamRotherham
FLC26/09/2020CardiffReading
FLC26/09/2020DerbyBlackburn
 
Upvote 0
Assuming the HomeTeam list is in column c, Something like this should give you the desired results for the home count, then change to column D for the away count.
Excel Formula:
=COUNTIF(C2:C$1500,C2)<=5
 
Upvote 0
Hi Jason

Thanks for the quick reply - works perfectly. Here was me trying to massively overcomplicate things using OFFSET when there's such a simple solution!!
 
Upvote 0
In the grand tradition of this thread, I have a problem which is very similar to the question posed by DeeEmmEss in 2018 and answered successfully by Aladin Akyurek.

Although I am not using goals scored as the basis of my method, I can easily substitute my ratings once a solution has been found. The data shown is the same as the DeeEmmEss original except that the date order is reversed as that is how the spreadsheet would build over a season when I am adding new results. The two additional columns, I and J, are effectively the same figure that is produced by the solution formula box G3 in Aladin’s answer, which I did by amending the original formula slightly

However, although this allows me to produce new ratings per team for upcoming matches based on the last n games, what I can’t do is analyse previous season results because my amended formula produces the same result for every occurrence of a particular team’s name. So although it correctly calculates the last 6 match (home or away) goal total, it changes every previous figure for that team to the same total. Try as I might I can’t resolve this. For clarity I have added two more columns, L and M, showing what the correct figures should be.

Any assistance would be greatly appreciated

Book2.xlsx
ABCDEFGHIJKLM
1DateHomeTeamAwayTeamFTHGFTAG2Total goals last n games from formulaTotal goals last 2 games actual
231/01/2018ChelseaBournemouth03Watford1303
331/01/2018EvertonLeicester2121221
431/01/2018Man CityWest Brom304130
531/01/2018NewcastleBurnley112311
631/01/2018SouthamptonBrighton111611
703/02/2018ArsenalEverton511151
803/02/2018BournemouthStoke213121
903/02/2018BrightonWest Ham316231
1003/02/2018BurnleyMan City113424
1103/02/2018LeicesterSwansea112521
1203/02/2018Man UnitedHuddersfield205220
1303/02/2018West BromSouthampton231124
1404/02/2018Crystal PalaceNewcastle112220
1504/02/2018LiverpoolTottenham226322
1605/02/2018WatfordChelsea412141
1710/02/2018EvertonCrystal Palace311242
1810/02/2018Man CityLeicester514262
1910/02/2018StokeBrighton111624
2010/02/2018SwanseaBurnley105321
2110/02/2018TottenhamArsenal103135
2210/02/2018West HamWatford202234
2311/02/2018HuddersfieldBournemouth412343
2411/02/2018NewcastleMan United102522
2511/02/2018SouthamptonLiverpool021634
2612/02/2018ChelseaWest Brom301142
2724/02/2018BournemouthNewcastle223233
2824/02/2018BrightonSwansea416552
2924/02/2018BurnleySouthampton113111
3024/02/2018LeicesterStoke112122
3124/02/2018LiverpoolWest Ham416263
3224/02/2018WatfordEverton102113
3324/02/2018West BromHuddersfield121216
3425/02/2018Crystal PalaceTottenham012312
3525/02/2018Man UnitedChelsea215124
3601/03/2018ArsenalMan City031408
3703/03/2018BurnleyEverton213131
3803/03/2018LeicesterBournemouth112323
3903/03/2018LiverpoolNewcastle206262
4003/03/2018SouthamptonStoke001111
4103/03/2018SwanseaWest Ham415252
4203/03/2018TottenhamHuddersfield203232
4303/03/2018WatfordWest Brom102121
4404/03/2018BrightonArsenal216161
4504/03/2018Man CityChelsea104141
4605/03/2018Crystal PalaceMan United232525
Sheet1
Cell Formulas
RangeFormula
I2:I4I2=SUM(IF(ROW($A$2:$A$59)>=LARGE(IF($B$2:$C$59=B$2,ROW($A$2:$A$59)),MIN($G$1,COUNTIFS($B$2:$C$59,B2))),IF($B$2:$C$59=B2,$D$2:$E$59)))
I5:J46,J2:J4J2=SUM(IF(ROW($A$2:$A$59)>=LARGE(IF($B$2:$C$59=C2,ROW($A$2:$A$59)),MIN($G$1,COUNTIFS($B$2:$C$59,C2))),IF($B$2:$C$59=C2,$D$2:$E$59)))
G3G3=SUM(IF(ROW($A$2:$A$59)>=LARGE(IF($B$2:$C$59=G$2,ROW($A$2:$A$59)),MIN($G$1,COUNTIFS($B$2:$C$59,G$2))),IF($B$2:$C$59=G$2,$D$2:$E$59)))
Press CTRL+SHIFT+ENTER to enter array formulas.
 
Upvote 0
As this is a significantly different question from the op, please start a new thread of your own.
Also if you are trying to do it season by season it would help if you supplied more than one years data.
 
Upvote 0
As this is a significantly different question from the op, please start a new thread of your own.
Also if you are trying to do it season by season it would help if you supplied more than one years data.
 
Upvote 0
Thank you for your quick response. Happy to post as a new thread. Only posted here as one of the other participants had a very similar question although admittedly he wasn't the op. I can post more data if required although I am not sure how useful that would be. I will try to explain my aim a bit more clearly in the new post as the last attempt was a bit rambling!
 
Upvote 0

Forum statistics

Threads
1,215,200
Messages
6,123,601
Members
449,109
Latest member
Sebas8956

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