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
 
Here an example (I know there are differences in "," and ";" but this is only because I am using a german version of excel, all english commands like ROW etc. still apply)

image.png
 
Upvote 0

Excel Facts

What is the fastest way to copy a formula?
If A2:A50000 contain data. Enter a formula in B2. Select B2. Double-click the Fill Handle and Excel will shoot the formula down to B50000.
Here an example (I know there are differences in "," and ";" but this is only because I am using a german version of excel, all english commands like ROW etc. still apply)
[...]

Please try to post the sample of this exhibit in an Excel readable form along with the desired result.
 
Upvote 0
Please try to post the sample of this exhibit in an Excel readable form along with the desired result.

Team HomeTeam AwayGoal Difference
AG3
BF3
CA2
DB0
EC1
GA0
AD2
BA1
CG0
DG4
EF3
FE0
GC2
AE2
BE0
CF0
DC1
EV2
FA3
GD0
AG3
BF3
CA2
DB0
EC1
CF0
CA2

<colgroup><col><col><col></colgroup><tbody>
</tbody>


And this is the code: =SUM(IF(ROW($C$2:$C$27)>=LARGE(IF($A$2:$A$27=$A$27;ROW($C$2:$C$27));MIN(6;COUNTIF($A$2:$A$27;$A$27)));IF($A$2:$A$27=$A$27;$C$2:$C$27)))

Again I had to replace the "," by the ";"

The formula retunrs the answer #NUM

Thank you for your help!
 
Upvote 0
Team HomeTeam AwayGoal Difference
AG3
BF3
CA2
DB0
EC1
GA0
AD2
BA1
CG0
DG4
EF3
FE0
GC2
AE2
BE0
CF0
DC1
EV2
FA3
GD0
AG3
BF3
CA2
DB0
EC1
CF0
CA2

<tbody>
</tbody>


And this is the code: =SUM(IF(ROW($C$2:$C$27)>=LARGE(IF($A$2:$A$27=$A$27;ROW($C$2:$C$27));MIN(6;COUNTIF($A$2:$A$27;$A$27)));IF($A$2:$A$27=$A$27;$C$2:$C$27)))

Again I had to replace the "," by the ";"

The formula retunrs the answer #NUM

Thank you for your help!

I get 4 as result, #NUM!.

This formula refers to A27 as a condition, a part of the data, which is not very wise.

Care to state what you want to calculate exactly?
 
Upvote 0
I get 4 as result, #NUM!.

This formula refers to A27 as a condition, a part of the data, which is not very wise.

Care to state what you want to calculate exactly?

Team HomeTeam AwayGoal DifferenceDate of MatchNo of Match
AG327.01.201427
BF326.01.201426
CA225.01.201425
DB024.01.201424
EC123.01.201423
GA022.01.201422
AD221.01.201421
BA120.01.201420
CG019.01.201419
DG418.01.201418
EF317.01.201417
FE016.01.201416
GC215.01.201415
AE214.01.201414
BE013.01.201413
CF012.01.201412
DC111.01.201411
EV210.01.201410
FA309.01.20149
GD008.01.20148
AG307.01.20147
BF306.01.20146
CA205.01.20145
DB004.01.20144
EC103.01.20143
CF002.01.20142
CA201.01.20141

<colgroup><col><col><col><col><col></colgroup><tbody>
</tbody>
=SUM(IF(ROW($C$2:$C$27)>=LARGE(IF($A$2:$A$27=$A$27;ROW($C$2:$C$27));MIN(3;COUNTIF($A$2:$A$27;$A$27)));IF($A$2:$A$27=$A$27;$C$2:$C$27)))

The formula should return the total goal differences for the latest three games of a certain home team for a certain date. In this case of the home team which is in A27 = Team called "C". In example, for the date in bolt letters, the row with date 25.01.2014. I want to add an extra column in which I will have a trend for the three latest home games of team C. Thus this extram column should add, and only add, the last three Goal differences for home matches of team C (i.e. 0+0+2 = 2). This extra column I want to add for any row, thus the trend will be different for each team, depending on the date (and thus the result of the three home games before this date).

I need this information for a regression analysis as I want to control for the quality/trend for a team.

I hope I could make myself clear. Thank you again for your patience and help!
 
Upvote 0
Team HomeTeam AwayGoal DifferenceDate of MatchNo of Match
AG327.01.201427
BF326.01.201426
CA225.01.201425
DB024.01.201424
EC123.01.201423
GA022.01.201422
AD221.01.201421
BA120.01.201420
CG019.01.201419
DG418.01.201418
EF317.01.201417
FE016.01.201416
GC215.01.201415
AE214.01.201414
BE013.01.201413
CF012.01.201412
DC111.01.201411
EV210.01.201410
FA309.01.20149
GD008.01.20148
AG307.01.20147
BF306.01.20146
CA205.01.20145
DB004.01.20144
EC103.01.20143
CF002.01.20142
CA201.01.20141

<tbody>
</tbody>
=SUM(IF(ROW($C$2:$C$27)>=LARGE(IF($A$2:$A$27=$A$27;ROW($C$2:$C$27));MIN(3;COUNTIF($A$2:$A$27;$A$27)));IF($A$2:$A$27=$A$27;$C$2:$C$27)))

The formula should return the total goal differences for the latest three games of a certain home team for a certain date. In this case of the home team which is in A27 = Team called "C". In example, for the date in bolt letters, the row with date 25.01.2014. I want to add an extra column in which I will have a trend for the three latest home games of team C. Thus this extram column should add, and only add, the last three Goal differences for home matches of team C (i.e. 0+0+2 = 2). This extra column I want to add for any row, thus the trend will be different for each team, depending on the date (and thus the result of the three home games before this date).

I need this information for a regression analysis as I want to control for the quality/trend for a team.

I hope I could make myself clear. Thank you again for your patience and help!



1) I do not understand why you insist on C being in A27 instead of having this criterion outside of the data area, say in E1.

2) The same holds for 25.01.2015. Why not have this criterion date outside the data area, say in F1?

3) You say "for a certain date", i.e., 25.01.2015. Then you go to indicate the C dates 19.01.2015, 12.01.2015, and 05.01.2015. What is the relation of these dates with the criterion date of 25.01.2015?
 
Upvote 0
1) I do not understand why you insist on C being in A27 instead of having this criterion outside of the data area, say in E1.

2) The same holds for 25.01.2015. Why not have this criterion date outside the data area, say in F1?

3) You say "for a certain date", i.e., 25.01.2015. Then you go to indicate the C dates 19.01.2015, 12.01.2015, and 05.01.2015. What is the relation of these dates with the criterion date of 25.01.2015?


1) I don't insist on this field. I just took it over from this thread, doesn't matter in which field it is. F1 is totally fine^^

2) Same here

3) The relation of these dates is that those dates represent the last three home games of Team C. They acctually do not really matter and should not be important for the formula. It was just a sidenote helping to understand what I am looking for. I highlightet the last three home games in red in the list above.
 
Upvote 0
Here my test file: Forum Test.xlsx (0.01 MegaByte) , If someone would like to fill in directly the corret formula. Please feel free to do so :(

Otherwise a link with a screenshot of my improved formula and how it looks like: Pic-Upload.de - image.png

{=IF(COUNTIF(A3:A49,A2)>0,SUM(IF((A3:A49=A2)*(COUNTIF(A2,A3:A49)*(100-ROW(A3:$A49))>=LARGE(COUNTIF(A2,A3:A49)*(100-ROW(A3:$A49)),MIN(COUNTIF(A3:A49,A2),3))),C3:C49)),"")}
 
Upvote 0
1) I don't insist on this field. I just took it over from this thread, doesn't matter in which field it is. F1 is totally fine^^

2) Same here

3) The relation of these dates is that those dates represent the last three home games of Team C. They acctually do not really matter and should not be important for the formula. It was just a sidenote helping to understand what I am looking for. I highlightet the last three home games in red in the list above.

Ok. Thanks.

~
Row\Col
A​
B​
C​
D​
E​
F​
G​
1​
Team HomeTeam AwayGoal DifferenceDate of MatchLast
3​
2​
AG
3​
1/27/2014​
Team homeC
3​
BF
3​
1/26/2014​
Total
2
4​
CA
2​
1/25/2014​
5​
DB
0​
1/24/2014​
6​
EC
1​
1/23/2014​
7​
GA
0​
1/22/2014​
8​
AD
2​
1/21/2014​
9​
BA
1​
1/20/2014​
10​
CG
0​
1/19/2014​
11​
DG
4​
1/18/2014​
12​
EF
3​
1/17/2014​
13​
FE
0​
1/16/2014​
14​
GC
2​
1/15/2014​
15​
AE
2​
1/14/2014​
16​
BE
0​
1/13/2014​
17​
CF
0​
1/12/2014​
18​
DC
1​
1/11/2014​
19​
EV
2​
1/10/2014​
20​
FA
3​
1/9/2014​
21​
GD
0​
1/8/2014​
22​
AG
3​
1/7/2014​
23​
BF
3​
1/6/2014​
24​
CA
2​
1/5/2014​
25​
DB
0​
1/4/2014​
26​
EC
1​
1/3/2014​
27​
CF
0​
1/2/2014​

G2, control+shift+enter, not just enter:

=SUM(IF(ROW($C$2:$C$27)>=LARGE(IF($A$2:$A$27=G$2,ROW($C$2:$C$27)),MIN(G$1,COUNTIFS($A$2:$A$27,G$2))),IF($A$2:$A$27=G$2,$C$2:$C$27)))<strike></strike>

This sums the goal differences associated with the last three games of C as team home. Is this what you are after?
 
Upvote 0
Ok. Thanks.

~
Row\Col
A​
B​
C​
D​
E​
F​
G​
1​
Team HomeTeam AwayGoal DifferenceDate of MatchLast
3​
2​
AG
3​
1/27/2014​
Team homeC
3​
BF
3​
1/26/2014​
Total
2
4​
CA
2​
1/25/2014​
5​
DB
0​
1/24/2014​
6​
EC
1​
1/23/2014​
7​
GA
0​
1/22/2014​
8​
AD
2​
1/21/2014​
9​
BA
1​
1/20/2014​
10​
CG
0​
1/19/2014​
11​
DG
4​
1/18/2014​
12​
EF
3​
1/17/2014​
13​
FE
0​
1/16/2014​
14​
GC
2​
1/15/2014​
15​
AE
2​
1/14/2014​
16​
BE
0​
1/13/2014​
17​
CF
0​
1/12/2014​
18​
DC
1​
1/11/2014​
19​
EV
2​
1/10/2014​
20​
FA
3​
1/9/2014​
21​
GD
0​
1/8/2014​
22​
AG
3​
1/7/2014​
23​
BF
3​
1/6/2014​
24​
CA
2​
1/5/2014​
25​
DB
0​
1/4/2014​
26​
EC
1​
1/3/2014​
27​
CF
0​
1/2/2014​

<tbody>
</tbody>


G2, control+shift+enter, not just enter:

=SUM(IF(ROW($C$2:$C$27)>=LARGE(IF($A$2:$A$27=G$2,ROW($C$2:$C$27)),MIN(G$1,COUNTIFS($A$2:$A$27,G$2))),IF($A$2:$A$27=G$2,$C$2:$C$27)))<strike></strike>

This sums the goal differences associated with the last three games of C as team home. Is this what you are after?


Thank you so much Aladin Akyurek!!
This was exactly what I was lookig for!!
 
Upvote 0

Forum statistics

Threads
1,215,197
Messages
6,123,581
Members
449,108
Latest member
rache47

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