Sum last X amount of occurrences in a column

jack109

Board Regular
Joined
May 10, 2020
Messages
50
Office Version
  1. 365
Platform
  1. Windows
Hi
I've tried looking around but I can quite find a formula to meet my needs. What I want is for the formula to sum column B using the last 3 occurrences of a value set in D1 using column A (PERSON).

So for example if I was to use Alice , using the data below the sum of Alice would be 85 (16,49,20).

I would like the formula to work its way up from the last entry as this data will grow

I've posted a table below, had to use the table only method as other option is freezing my excel.

PERSONAMOUNT
ALICE11
TREVOR50
TREVOR18
BECKY28
IAN14
TREVOR33
DAVID25
BECKY45
TREVOR27
ALICE20
IAN5
TREVOR49
DAVID17
IAN47
BECKY34
BECKY28
DAVID17
ALICE49
BECKY34
DAVID38
IAN17
TREVOR29
ALICE16
IAN42
IAN48
 

Excel Facts

Did you know Excel offers Filter by Selection?
Add the AutoFilter icon to the Quick Access Toolbar. Select a cell containing Apple, click AutoFilter, and you will get all rows with Apple
A good usecase for `TAKE()`:

Book1
ABCD
1PersonAmountALICE
2ALICE1185
3TREVOR50
4TREVOR18
5BECKY28
6IAN14
7TREVOR33
8DAVID25
9BECKY45
10TREVOR27
11ALICE20
12IAN5
13TREVOR49
14DAVID17
15IAN47
16BECKY34
17BECKY28
18DAVID17
19ALICE49
20BECKY34
21DAVID38
22IAN17
23TREVOR29
24ALICE16
25IAN42
26IAN48
Sheet6
Cell Formulas
RangeFormula
D2D2=SUM(TAKE(FILTER(B:B,A:A=D1),-3))
 
Upvote 0
Solution
How about
Excel Formula:
=SUM(TAKE(FILTER(B2:B100,A2:A100=D1),-3))
 
Upvote 0
Thanks , one more question could this be adapted so that it would use two criterias eg. column C would now be YES/NO so count the last 3 "Alice" only if "YES" is adjacent in column C??
 
Upvote 0
How about
Excel Formula:
=SUM(TAKE(FILTER(B2:B100,(A2:A100=D1)*(C2:C100="yes")),-3))
 
Upvote 0
Glad we could help & thanks for the feedback.
 
Upvote 0
Sorry to be a pain, how would you modify this formula to count instead of Sum. I'd like the formula to Count how many times "YES" appears in the last 3 occurrences of "Alice". I've had a go myself by trying to use COUNT but to no avail.

Cheers 😬
 
Upvote 0
Book1
ABCD
1PersonAmountValALICE
2ALICE11YES1
3TREVOR50NO
4TREVOR18YES
5BECKY28NO
6IAN14YES
7TREVOR33NO
8DAVID25YES
9BECKY45NO
10TREVOR27YES
11ALICE20NO
12IAN5YES
13TREVOR49NO
14DAVID17YES
15IAN47NO
16BECKY34YES
17BECKY28NO
18DAVID17YES
19ALICE49NO
20BECKY34YES
21DAVID38NO
22IAN17YES
23TREVOR29NO
24ALICE16YES
25IAN42NO
26IAN48YES
Sheet6
Cell Formulas
RangeFormula
D2D2=SUM(--(TAKE(FILTER(C:C,A:A=D1),-3)="Yes"))
 
Upvote 0
Another option
Excel Formula:
=LET(f,TAKE(FILTER(C2:C100,A2:A100=D1,),-3),ROWS(FILTER(f,f="yes")))
 
Upvote 0

Forum statistics

Threads
1,215,094
Messages
6,123,069
Members
449,092
Latest member
ipruravindra

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