Difference of last N rows Based on multiple conditions using two columns

popov

New Member
Joined
Jan 15, 2022
Messages
2
Office Version
  1. 365
Platform
  1. Windows
Hello,

I have the following problem. I would like to calculate the goal difference for the last N games for each team specified (assuming the Date is already sorted, ie. 6 being the latest game played).

For example if I want to calculate the goal differences for England in their last 3 games I would like to have (1-1) + (3-0) + (2-1) = 4

I hope this is clear enough.

Thank you in advance.

Kind regards,
Pierre
 

Attachments

  • ex.png
    ex.png
    7.8 KB · Views: 13

Excel Facts

Add Bullets to Range
Select range. Press Ctrl+1. On Number tab, choose Custom. Type Alt+7 then space then @ sign (using 7 on numeric keypad)
testing.xlsx
ABCDEFGHI
1last Ndelta
2englandgermany60England34
3italyspain51germany11
4usaengland12greece1-3
5englandgreece30romania2-1
6germanyromania32usa1-1
7romaniaengland1180
Blad6
Cell Formulas
RangeFormula
H2:H6H2=COUNTIF($B$4:$C$7,G2)
I2:I6I2=SUMPRODUCT(($D$4:$D$7-$E$4:$E$7)*(($B$4:$C$7=G2)-($C$4:$C$7=G2)))
H7:I7H7=SUM(H2:H6)
 
Upvote 0
testing.xlsx
ABCDEFGHI
1last Ndelta
2englandgermany60England34
3italyspain51germany11
4usaengland12greece1-3
5englandgreece30romania2-1
6germanyromania32usa1-1
7romaniaengland1180
Blad6
Cell Formulas
RangeFormula
H2:H6H2=COUNTIF($B$4:$C$7,G2)
I2:I6I2=SUMPRODUCT(($D$4:$D$7-$E$4:$E$7)*(($B$4:$C$7=G2)-($C$4:$C$7=G2)))
H7:I7H7=SUM(H2:H6)
Hi Bsalv,

Thank you for the quick response!

Would it be possible to select all the cells and automatically calculate what you calculated on the basis of each team's last 3 games. That it instead of selecting the cells on which to perform your formula, to be able to select the whole range and use the value in Last N as a parameter that I can later change and the formula for the delta to still be valid? I hope this is clear enough!

Kind regards,
Pierre
 
Upvote 0
i'm not strong in matrixformulas, so yes, it's possible, but i can't give an answer.
 
Upvote 0
I feel sure there must be a simpler way, but how about
+Fluff 1.xlsm
ABCDEFGHI
1
21englandgermany60England34
32italyspain51
43usaengland12
54englandgreece30
65germanyromania32
76romaniaengland11
8
Lists
Cell Formulas
RangeFormula
I2I2=LET(f,SORT(FILTER(A2:E7,(B2:B7=G2)+(C2:C7=G2)),1,-1),a,INDEX(f,SEQUENCE(H2),{2,3,4,5}),SUM((INDEX(a,,3)-INDEX(a,,4))*IF(INDEX(a,,1)=G2,1,-1)))
 
Upvote 0
Not any better, but here another way.

Book3
ABCDEFGHI
1
21englandgermany60England34
32italyspain51
43usaengland12
54englandgreece30
65germanyromania32
76romaniaengland11
Sheet1
Cell Formulas
RangeFormula
I2I2=SUM(INDIRECT("D" & (MIN(ROW(A2:A7))+ROWS(A2:A7))-H2 &":D7"),-INDIRECT("E" & (MIN(ROW(A2:A7))+ROWS(A2:A7))-H2 &":E7"))
 
Upvote 0
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: Difference of last N rows Based on multiple conditions using two columns
If you have posted the question at more 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 0

Forum statistics

Threads
1,214,988
Messages
6,122,620
Members
449,092
Latest member
amyap

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