AVERAGEIFS for last X records in a customer list?

GaryV

New Member
Joined
Mar 23, 2018
Messages
14
I have a dataset that looks a bit like this:

Cust A1/1/18345
Cust A2/1/18634
Cust A3/1/18567
Cust B11/1/181209
Cust B12/1/181340
Cust B1/1/181500
Cust B2/1/181654
Cust B3/1/181567
Cust C2/1/18423
Cust C3/1/18450
Cust D3/1/181690

<tbody>
</tbody>

The record count can vary by customer. I'm looking to average the 3rd column's numbers, for up to the last 3 rows, by customer.

I have a separate list of unique customer ID's and I've been experimenting with AVERAGEIFS, Offset, etc., but can't seem to get the logic correct.

Could I kindly ask for an experts view on this and for any recommendations on a solution?

Many thanks!!
G
 

Excel Facts

How can you automate Excel?
Press Alt+F11 from Windows Excel to open the Visual Basic for Applications (VBA) editor.
Thanks Aladin, will give that one a go, too!

Either you have the customer conditions in a separate range like below...

=AVERAGE(IF(ROW($C$2:$C$12)>=LARGE(IF($A$2:$A$12=F2,IF(ISNUMBER($C$2:$C$12),ROW($C$2:$C$12))),MIN(3,COUNTIFS($A$2:$A$12,F2))),IF($A$2:$A$12=F2,IF(ISNUMBER($C$2:$C$12),$C$2:$C$12))))

In G2 control+shift+enter, not just enter, and copy down:

=AVERAGE(IF(ROW($C$2:$C$12)>=LARGE(IF($A$2:$A$12=F2,IF(ISNUMBER($C$2:$C$12),ROW($C$2:$C$12))),MIN(3,COUNTIFS($A$2:$A$12,F2))),IF($A$2:$A$12=F2,IF(ISNUMBER($C$2:$C$12),$C$2:$C$12))))

Or like below where processing creates an additional range...

Row\Col
A​
B​
C​
D​
1​
customerdatevaluelast 3 avg
2​
Cust A
1/1/2018
345
515.33​
3​
Cust A
2/1/2018
634
515.33​
4​
Cust A
3/1/2018
567
515.33​
5​
Cust B
11/1/2018
1209
1573.67​
6​
Cust B
12/1/2018
1340
1573.67​
7​
Cust B
1/1/2018
1500
1573.67​
8​
Cust B
2/1/2018
1654
1573.67​
9​
Cust B
3/1/2018
1567
1573.67​
10​
Cust C
2/1/2018
423
436.5​
11​
Cust C
3/1/2018
450
436.5​
12​
Cust D
3/1/2018
1690
1690​

In D2 control+shift+enter, not just enter, and copy down:

=IF(ISNA(MATCH($A2,$A$1:A1,0)),ROUND(AVERAGE(IF(ROW($C$2:$C$12)>=LARGE(IF($A$2:$A$12=$A2,IF(ISNUMBER($C$2:$C$12),ROW($C$2:$C$12))),MIN(3,COUNTIFS($A$2:$A$12,$A2))),IF($A$2:$A$12=$A2,IF(ISNUMBER($C$2:$C$12),$C$2:$C$12)))),2),VLOOKUP($A2,$A$1:$D1,4,0))

ROUND is added here for a nicer output.
 
Upvote 0

Forum statistics

Threads
1,216,742
Messages
6,132,453
Members
449,729
Latest member
davelevnt

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