Calculate last 5 soccer team goals using data from another sheet on same workbook.

jfriedman

New Member
Joined
Jan 18, 2024
Messages
11
Office Version
  1. 2021
Platform
  1. MacOS
Hopefully someone can help me with this Excel problem that I'm trying to solve. I'll try to be as clear as possible. I'm using Excel for Mac, version 16.81.

I have a workbook called SoccerRatings. In this workbook I have Sheet1 and row 1 contains the headings. The columns are named as such:

A - Date

B - Total Goals

C - Home Side

D - Away Side

E - Home Attack

F - Home Defence

G - Home Rating

H - Away Attack

I - Away Defence

J - Away Rating

K - Rating Diff

L - Home Score

M - Away Score

N - Expected Goals

O - Odds

P - Predicted

Q - Value

My area of interest lies in calculating the columns E F H I on Sheet1 using data from Sheet2 and Sheet3.

Sheet2 relates to results from the home team. Sheet3 relates to results for the away team. I seperate these to avoid confusion. I download these soccer results from a historic provider.

In Sheet2, row 1 contains the column headings. The columns are named:

A - Date

B - Home

C - Away

D - Home Goals

E - Away Goals



In Sheet2, I have everything sorted alphabetically by column B, which is the name of the Home team, and I have posted a picture to illustrate this. Please note that everything falls into date order that these teams played, which is a great help.

For example, say Arsenal are playing as the Home Team, how can I calculate the goals from their last 5 games, as listed on Sheet2, and have that total appear in Sheet1 under Home Attack (column E)?

Sheet3 is sorted by Away Team in date order, so I'm guessing whatever I do for the Home Team, it'll be interchangeable for the Away Team too.

The data in Sheet2 and Sheet3 will be constantly updated, but I always need the total sum to be drawn from the last 5 games.

I need to be able to do this for the Home Team and Away Team. I download fixtures every week, so I hope I can just cut and paste what teams are playing into the Home Side and Away Side columns, and numbers will do the rest for me.

My question is - how can I do this? I've been stumped on this for a few weeks and am no further on.

The formulas need to be dynamic to account for the different team names.


My Excel understanding is very basic, and I tried to piece together some formulas, which don't work I'm afraid:

This is for the Home Attack box.

=SUMIFS(Sheet2!$D:$D,Sheet2!$B:$B,Sheet1!C2,Sheet2!$A:$A,">"&MAX(IF(Sheet2!$B:$B=Sheet1!C2,Sheet2!$A

Home attack -

=AVERAGEIFS(OFFSET(Sheet2!$D$2, MATCH(C2, Sheet2!$B$2:$B$100, 0)-5, 0, 5, 1), Sheet2!$B$2:$B$100, C2)

Home defence:

=AVERAGEIFS(OFFSET(Sheet2!$E$2, MATCH(C2, Sheet2!$B$2:$B$100, 0)-5, 0, 5, 1), Sheet2!$B$2:$B$100, C2)

Away Attack:

=AVERAGEIFS(OFFSET(Sheet2!$D$2, MATCH(D2, Sheet2!$C$2:$C$100, 0)-5, 0, 5, 1), Sheet2!$C$2:$C$100, D2)

Away Defence:

=AVERAGEIFS(OFFSET(Sheet2!$E$2, MATCH(D2, Sheet2!$C$2:$C$100, 0)-5, 0, 5, 1), Sheet2!$C$2:$C$100, D2)

Sheet1 Contains this:

SoccerRatings_v1.xlsx
ABCDEFGHIJKLMNOPQ
1DATETOTAL GOALSHOME SIDEAWAY SIDEHOME ATTACKHOME DEFENCEHOME RATINGAWAY ATTACKAWAY DEFENCEAWAY RATINGRATING DIFFHOME SCOREAWAY SCOREGOALSODDSESTIMATED ODDSVALUE
2Arsenal#REF!#REF!#REF!0.00#REF!#REF!#REF!#REF!#REF!#REF!
3Arsenal#REF!#REF!0.00#REF!0.00#REF!#REF!#REF!#REF!
4Arsenal#REF!#REF!0.00#REF!0.00#REF!#REF!#REF!#REF!
Sheet1
Cell Formulas
RangeFormula
E2E2=AVERAGEIFS(OFFSET(Sheet2!$D$2, MATCH(C2, Sheet2!$B$2:$B$100, 0)-5, 0, 5, 1), Sheet2!$B$2:$B$100, C2)
F2F2=AVERAGEIFS(OFFSET(Sheet2!$E$2, MATCH(C2, Sheet2!$B$2:$B$100, 0)-5, 0, 5, 1), Sheet2!$B$2:$B$100, C2)
G2:G4,J2:J4G2=(E2-F2)/6
F3F3=AVERAGEIFS(OFFSET(Sheet2!$E$2, MATCH(C2, Sheet2!$B$2:$B$100, 0)-5, 0, 5, 1), Sheet2!$B$2:$B$100, C2)
F4F4=AVERAGEIFS(OFFSET(Sheet2!$E$2, MATCH(C2, Sheet2!$B$2:$B$100, 0)-5, 0, 5, 1), Sheet2!$B$2:$B$100, C2)
K2:K4K2=G2-J2
L2:L4L2=((E2+I2)/6)/2
M2:M4M2=((H2+F2)/6)/2
N2:N4N2=L2+M2
P2:P4P2=(4-K2)/2+1
Q2:Q4Q2=O2/P2*100



Sheet 2 (sorted by Home Team and in date order) contains this:

SoccerRatings_v1.xlsx
ABCDE
1DateHomeTeamAwayTeamHomeGoalsAwayGoals
28/12/23ArsenalNott'm Forest21
38/26/23ArsenalFulham22
49/3/23ArsenalMan United31
59/24/23ArsenalTottenham22
610/8/23ArsenalMan City10
710/28/23ArsenalSheffield United50
811/11/23ArsenalBurnley31
912/2/23ArsenalWolves21
1012/17/23ArsenalBrighton20
1112/28/23ArsenalWest Ham02
128/20/23Aston VillaEverton40
139/16/23Aston VillaCrystal Palace31
149/30/23Aston VillaBrighton61
Sheet2



Sheet 3 (sorted by away team and in date order)

SoccerRatings_v1.xlsx
ABCDE
1DateHomeTeamAwayTeamHomeGoalsAwayGoals
28/21/23Crystal PalaceArsenal01
39/17/23EvertonArsenal01
49/30/23BournemouthArsenal04
510/21/23ChelseaArsenal22
611/4/23NewcastleArsenal10
711/25/23BrentfordArsenal01
812/5/23LutonArsenal34
912/9/23Aston VillaArsenal10
1012/23/23LiverpoolArsenal11
1112/31/23FulhamArsenal21
128/12/23NewcastleAston Villa51
138/27/23BurnleyAston Villa13
Sheet3
 
Thanks again! Just wondering why you chose to put the results part on Sheet1? Not doubting your excellent work - just trying to understand and learn from your experience.
 
Upvote 0

Excel Facts

Fastest way to copy a worksheet?
Hold down the Ctrl key while dragging tab for Sheet1 to the right. Excel will make a copy of the worksheet.
You are welcome.
I did that because im lazy and it is easier for me to have the table in the same sheet when you are working with formulas (no need to change sheets, just click and drag the need range).
You can move them with cut and paste anywhere you like (any sheet).
 
Upvote 1
Welcome to the MrExcel Message Board!

Cross-posting (posting the same question in more than one forum) is not against our rules, but the method of doing so is covered by #13 of the Forum Rules.

Be sure to follow & read the link at the end of the rule too!

Cross posted at:
Calculate last 5 soccer team goals using data from another sheet on same workbook.

There is no need to repeat the link(s) provided above but if you have posted the question at other places, please provide links to those as well.

If you do cross-post in the future and also provide links, then there shouldn’t be a problem.
 
Upvote 1
I was doing some manual checking of the results of my spreadsheet and am have run into a bit of a problem. It seems that the results for the away teams are not correct.

Let us take the East Fife vs Spartans game, which is to be played tonight.

We can see that East Fife have scored a total of 7 goals in the last 5 home games - which is correct on the spreadsheet. It tells me that they have conceded 7 goals during those last 5 home games which is also correct.

If we look at Spartans it tells me they have scored 6 goals, when the actual total is 13.

As far as their away goals conceded the spreadsheet tells me 7, which is correct.


Let's take a look at Elgin vs Clyde.

The spreadsheet tells me Elgin have scored 5 goals at home, which is correct. They have conceded 7, which is also correct.

Clyde have scored 8 goals in their last 5 away games, the spreadsheet reports this as 2.

The spreadsheet reports Clyde have conceded 12, when the real total is 9.

For some reason the calculations don't appear to be accurate and I can't work out why. Would someone be able to review the formulas and see if there is an error, or if I'm making an error?

I have included the XL2BB data and uploaded the sheet. SoccerRatings_V1.zip

Many thanks.


SoccerRatings_V1.xlsx
ABCDEFGHIJKLMNOP
1481/30/24East FifeSpartans770.0067-0.200.201.401.32.702.702.9093.10
1491/30/24ElginClyde57-0.40212-2.001.601.700.92.603.102.20140.91
Sheet1
Cell Formulas
RangeFormula
D148:D149D148=LET(team, $B148, gamesDates, FILTER(Home[Date], Home[HomeTeam]=team), minDate, IFERROR(LARGE(gamesDates,5), MAX(gamesDates)), goals, FILTER(Home[HomeGoals], (Home[HomeTeam]=team)*(Home[Date]>=minDate)), SUM(goals) )
E148:E149E148=LET(team, $B148, homeGamesDates, FILTER(Home[Date], Home[HomeTeam]=team), minDate, IFERROR(LARGE(homeGamesDates,5), MAX(homeGamesDates)), goals, FILTER(Home[AwayGoals], (Home[HomeTeam]=team)*(Home[Date]>=minDate)), SUM(goals))
F148:F149,I148:I149F148=(D148-E148)/5
G148:G149G148=LET(team, $B148, homeGamesDates, FILTER(Away[Date], Away[AwayTeam]=team), minDate, IFERROR(LARGE(homeGamesDates,5), MAX(homeGamesDates)), goals, FILTER(Away[AwayGoals], (Away[AwayTeam]=team)*(Away[Date]>=minDate)), SUM(goals) )
H148:H149H148=LET(team, $B148, homeGamesDates, FILTER(Away[Date], Away[AwayTeam]=team), minDate, IFERROR(LARGE(homeGamesDates,5), MAX(homeGamesDates)), goals, FILTER(Away[HomeGoals], (Away[AwayTeam]=team)*(Away[Date]>=minDate)), SUM(goals) )
J148:J149J148=SUM(F148-I148)
K148:K149K148=SUM((D148+H148)/5)/2
L148:L149L148=SUM((G148+E148)/5)/2
M148:M149M148=SUM(K148+L148)
O148:O149O148=SUM(4-J148)/2+1
P148:P149P148=SUM(N148/O148)*100
Cells with Conditional Formatting
CellConditionCell FormatStop If True
M3:M164Cell Value>2.3textNO
P3:P164Cell Value>80textNO
 
Upvote 0
Giving this thread a gentle bump. Should I post my new query as another thread in the unanswered questions?
 
Upvote 0
The formula is working fine I think but it is searching for Elgin, not Clyde. If you edit the formula you will see the input cell is B149. The same happens to all the others.
I had the file i uploaded and the inputs we had was only for Home Side:

SoccerTeam.xlsx
ABCDEFGHIJKLMNOPQRSTUVWXYZAAABACADAE
1HomeAway
2DateTotal GoalsHome SideAway SideHome AttackHome DefenceHome RatingAway AttackAway DefenceAway RatingRating DiffHome ScoreAway ScoreExpected GoalsOddsPredictedValueDateHomeTeamAwayTeamHomeGoalsAwayGoalsDateHomeTeamAwayTeamHomeGoalsAwayGoals
3Arsenal1241,677012/08/2023ArsenalNott'm Forest2112/08/2023NewcastleAston Villa51
420/08/2023Aston VillaEverton4021/08/2023Crystal PalaceArsenal01
526/08/2023ArsenalFulham2227/08/2023BurnleyAston Villa13
603/09/2023ArsenalMan United3117/09/2023EvertonArsenal01
716/09/2023Aston VillaCrystal Palace3130/09/2023BournemouthArsenal04
824/09/2023ArsenalTottenham2221/10/2023ChelseaArsenal22
930/09/2023Aston VillaBrighton6104/11/2023NewcastleArsenal10
1008/10/2023ArsenalMan City1025/11/2023BrentfordArsenal01
1128/10/2023ArsenalSheffield United5005/12/2023LutonArsenal34
1211/11/2023ArsenalBurnley3109/12/2023Aston VillaArsenal10
1302/12/2023ArsenalWolves2123/12/2023LiverpoolArsenal11
1417/12/2023ArsenalBrighton2031/12/2023FulhamArsenal21
1528/12/2023ArsenalWest Ham02
Sheet1
Cell Formulas
RangeFormula
E3E3=LET(team, $C3, gamesDates, FILTER(Home[Date], Home[HomeTeam]=team), minDate, IFERROR(LARGE(gamesDates,5), MAX(gamesDates)), goals, FILTER(Home[HomeGoals], (Home[HomeTeam]=team)*(Home[Date]>=minDate)), SUM(goals) )
F3F3=LET(team, $C3, homeGamesDates, FILTER(Home[Date], Home[HomeTeam]=team), minDate, IFERROR(LARGE(homeGamesDates,5), MAX(homeGamesDates)), goals, FILTER(Home[AwayGoals], (Home[HomeTeam]=team)*(Home[Date]>=minDate)), SUM(goals))
G3,J3G3=(E3-F3)/5
H3H3=LET(team, $C3, homeGamesDates, FILTER(Away[Date], Away[AwayTeam]=team), minDate, IFERROR(LARGE(homeGamesDates,5), MAX(homeGamesDates)), goals, FILTER(Away[AwayGoals], (Away[AwayTeam]=team)*(Away[Date]>=minDate)), SUM(goals) )
I3I3=LET(team, $C3, homeGamesDates, FILTER(Away[Date], Away[AwayTeam]=team), minDate, IFERROR(LARGE(homeGamesDates,5), MAX(homeGamesDates)), goals, FILTER(Away[HomeGoals], (Away[AwayTeam]=team)*(Away[Date]>=minDate)), SUM(goals) )



If this is not correct, then change the input cell to the correct one.
 
Upvote 0
Solution
Thanks for your reply.

Unfortunately I am completely lost here.

As an example - I have Luton in twice as the away side, playing different home teams, and it's giving me completely different goals scored and goals conceded for each away game.

Many thanks :)



SoccerTeam.xlsx
ABCDEFGHIJ
2DateTotal GoalsHome SideAway SideHome AttackHome DefenceHome RatingAway AttackAway DefenceAway Rating
3Man CityWolves1471.41290.6
4ChelseaLuton1271612-1.2
5Man CityLuton1471.41290.6
Sheet1
Cell Formulas
RangeFormula
E3:E5E3=LET(team, $C3, gamesDates, FILTER(Home[Date], Home[HomeTeam]=team), minDate, IFERROR(LARGE(gamesDates,5), MAX(gamesDates)), goals, FILTER(Home[HomeGoals], (Home[HomeTeam]=team)*(Home[Date]>=minDate)), SUM(goals) )
F3:F5F3=LET(team, $C3, homeGamesDates, FILTER(Home[Date], Home[HomeTeam]=team), minDate, IFERROR(LARGE(homeGamesDates,5), MAX(homeGamesDates)), goals, FILTER(Home[AwayGoals], (Home[HomeTeam]=team)*(Home[Date]>=minDate)), SUM(goals))
G3:G5,J3:J5G3=(E3-F3)/5
H3:H5H3=LET(team, $C3, homeGamesDates, FILTER(Away[Date], Away[AwayTeam]=team), minDate, IFERROR(LARGE(homeGamesDates,5), MAX(homeGamesDates)), goals, FILTER(Away[AwayGoals], (Away[AwayTeam]=team)*(Away[Date]>=minDate)), SUM(goals) )
I3:I5I3=LET(team, $C3, homeGamesDates, FILTER(Away[Date], Away[AwayTeam]=team), minDate, IFERROR(LARGE(homeGamesDates,5), MAX(homeGamesDates)), goals, FILTER(Away[HomeGoals], (Away[AwayTeam]=team)*(Away[Date]>=minDate)), SUM(goals) )
 
Upvote 0
Sorry, it wont let me edit the above message.

I have it working - it was my stupidity and lack of understanding.

thanks again, as always, @felixstraube
 
Upvote 0

Forum statistics

Threads
1,224,812
Messages
6,181,105
Members
453,021
Latest member
Justyna P

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