Sumif ,but only upto where last 3 instances match

ste33uka

Active Member
Joined
Jan 31, 2020
Messages
473
Office Version
  1. 365
Platform
  1. Windows
Hi i have added a imige for better understanding,
Would anyone have a formula to sum column C,
when G1 matches column A and H1 matches column B, but only the last 3 instances where they match.
So in example answer would be 14.
Thanks
1111.png
 

Excel Facts

Copy a format multiple times
Select a formatted range. Double-click the Format Painter (left side of Home tab). You can paste formatting multiple times. Esc to stop
How about
+Fluff New.xlsm
ABCDEF
1Dogapple
235
3
4
5dogapple3
6catpear4
7frogpear5
8frogplum6
9catapple7
10dogapple8
11dogplum9
12catpear10
13horseapple11
14dogapple12
15frogplum13
16catapple14
17dogapple15
18
Data
Cell Formulas
RangeFormula
E2E2=SUM(INDEX($C$5:$C$21,AGGREGATE(14,6,(ROW($C$5:$C$21)-ROW($C$5)+1)/($A$5:$A$21=$E$1)/($B$5:$B$21=$F$1),{1,2,3})))


In future please post sample data using the XL2BB add-in, it saves us from having to create something ourselves.
 
Upvote 0
Try this one, array confirmed with Ctrl Shift Enter.

=SUMPRODUCT(SIGN(IFERROR(AGGREGATE(14,6,ROW(A5:A21)/(A5:A21=G1)/(B5:B21=H1),{1,2,3}),0)),C5:C23)

Might work, might not, can't test it on a screen capture, need XL2BB sample for that.
 
Upvote 0
How about
+Fluff New.xlsm
ABCDEF
1Dogapple
235
3
4
5dogapple3
6catpear4
7frogpear5
8frogplum6
9catapple7
10dogapple8
11dogplum9
12catpear10
13horseapple11
14dogapple12
15frogplum13
16catapple14
17dogapple15
18
Data
Cell Formulas
RangeFormula
E2E2=SUM(INDEX($C$5:$C$21,AGGREGATE(14,6,(ROW($C$5:$C$21)-ROW($C$5)+1)/($A$5:$A$21=$E$1)/($B$5:$B$21=$F$1),{1,2,3})))


In future please post sample data using the XL2BB add-in, it saves us from having to create something ourselves.
Thanks alot, im going to learn about xl2bb right now, thanks again
 
Upvote 0
Hi as a first test of xl2bb is this correct ?

del.xlsx
E
2
Sheet1
 
Upvote 0
You ned to select the cells you want to show.
 
Upvote 0
del.xlsx
ABCDEFGH
114applemark
2
3
4
5applemark12
6applemark12
7appleterry12
8applemark12
9appleterry12
10applestephen12
11applestephen12
12applestephen12
13applestephen1
14applemark1
15applemark1
16applemark12
17appleterry7
18applemark1
19pearmark1
20orangeterry9
21oranemark1
Sheet1
Cell Formulas
RangeFormula
E1E1=SUM(INDEX($C$5:$C$21,AGGREGATE(14,6,(ROW($C$5:$C$21)-ROW($C$5)+1)/($A$5:$A$21=$G$1)/($B$5:$B$21=$H$1),{1,2,3})))


is this correct?
 
Upvote 0
example1.xlsx
ABCDEFGH
114applemark
2
3
4
5appleterry12
6applestephen12
7appleterry12
8applemark5
9appleterry12
10applestephen12
11applestephen12
12applestephen12
13applestephen1
14applemark1
15applemark1
16applemark12
17appleterry7
18applemark1
19pearmark1
20orangeterry9
21oranemark1
22
23
24
25
Sheet1
Cell Formulas
RangeFormula
E1E1=SUM(INDEX($C$4:$C$777,AGGREGATE(14,6,(ROW($C$4:$C$777)-ROW($C$4)+1)/($A$4:$A$21=$G$1)/($B$4:$B$21=$H$1),{1,2,3})))


Hi the 1st example i have uploaded works fine,
But second example as there is not 3 matches i get value '#num!'
Is there a way it could just sum the last 2 instances in the second example?
Thanks

example2.xlsx
ABCDEFGH
1#NUM!applemark
2
3
4
5
6
7
8
9
10
11
12
13pearmark1
14orangeterry9
15oranemark1
16applemark12
17appleterry7
18applemark1
19pearmark1
20orangeterry9
21oranemark1
22
23
Sheet1
Cell Formulas
RangeFormula
E1E1=SUM(INDEX($C$4:$C$777,AGGREGATE(14,6,(ROW($C$4:$C$777)-ROW($C$4)+1)/($A$4:$A$21=$G$1)/($B$4:$B$21=$H$1),{1,2,3})))
 
Last edited:
Upvote 0
This one works

=SUMPRODUCT((ROW(A5:A21)=IFERROR(AGGREGATE(14,6,ROW(A5:A21)/(A5:A21=G1)/(B5:B21=H1),{1,2,3}),0))*C5:C21)
 
Upvote 0

Forum statistics

Threads
1,215,491
Messages
6,125,111
Members
449,205
Latest member
ralemanygarcia

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