Average Last n Values with multiple conditions

Jabe

New Member
Joined
Apr 29, 2024
Messages
13
Office Version
  1. 365
Platform
  1. Windows
Hi all,

I'm trying to average the last 5 values in a column after a number of conditions are met. In the attached example, is there a formula that would find the average of the number of days John's last 2 designs took?
PersonActionDays
AdamDesign1
JohnDesign7
CharlotteDesign4
AdamBuild30
DannyBuild27
PaulaDesign3
JohnBuild41
DannyDesign5
CharlotteDesign6
AdamBuild32
PaulaBuild36
JohnBuild33
CharlotteBuild29
JohnDesign2
DannyDesign4
AdamBuild19
PaulaBuild27
AdamDesign5
CharlotteDesign4
JohnDesign1
DannyBuild34
I'm thinking something with AVERAGEIFS and TAKE but I can't seem to get it to work myself!
 
how about
=AVERAGE(TAKE(FILTER(C2:C22,(A2:A22="john")*(B2:B22="design")),-2))
will be the last 2
Book2
ABCDEFGH
1PersonActionDaysaverageList for Info ONLY
2AdamDesign11.52
3JohnDesign71
4CharlotteDesign4
5AdamBuild30
6DannyBuild27
7PaulaDesign3
8JohnBuild41
9DannyDesign5
10CharlotteDesign6
11AdamBuild32
12PaulaBuild36
13JohnBuild33
14CharlotteBuild29
15JohnDesign2
16DannyDesign4
17AdamBuild19
18PaulaBuild27
19AdamDesign5
20CharlotteDesign4
21JohnDesign1
22DannyBuild34
23
Sheet1
Cell Formulas
RangeFormula
E2E2=AVERAGE(TAKE(FILTER(C2:C22,(A2:A22="john")*(B2:B22="design")),-2))
G2:G3G2=(TAKE(FILTER(C2:C22,(A2:A22="john")*(B2:B22="design")),-2))
Dynamic array formulas.
 
Upvote 0
Solution
I'm trying to average the last 5 values in a column
Then why are you trying to
average of the number of days John's last 2 designs took
As you haven't given the criteria, maybe
Excel Formula:
=LET(f,TAKE(FILTER(A2:C100,B2:B100="design"),-5),AVERAGE(FILTER(f,TAKE(f,,1)="john")))
 
Upvote 0
Then why are you trying to

As you haven't given the criteria, maybe
Excel Formula:
=LET(f,TAKE(FILTER(A2:C100,B2:B100="design"),-5),AVERAGE(FILTER(f,TAKE(f,,1)="john")))
Apologies, my original post was confusing. I can't publish my actual data on here so had to make a representative example and making enough data to match my actual problem was too time consuming!
 
Upvote 0
how about
=AVERAGE(TAKE(FILTER(C2:C22,(A2:A22="john")*(B2:B22="design")),-2))
will be the last 2
Book2
ABCDEFGH
1PersonActionDaysaverageList for Info ONLY
2AdamDesign11.52
3JohnDesign71
4CharlotteDesign4
5AdamBuild30
6DannyBuild27
7PaulaDesign3
8JohnBuild41
9DannyDesign5
10CharlotteDesign6
11AdamBuild32
12PaulaBuild36
13JohnBuild33
14CharlotteBuild29
15JohnDesign2
16DannyDesign4
17AdamBuild19
18PaulaBuild27
19AdamDesign5
20CharlotteDesign4
21JohnDesign1
22DannyBuild34
23
Sheet1
Cell Formulas
RangeFormula
E2E2=AVERAGE(TAKE(FILTER(C2:C22,(A2:A22="john")*(B2:B22="design")),-2))
G2:G3G2=(TAKE(FILTER(C2:C22,(A2:A22="john")*(B2:B22="design")),-2))
Dynamic array formulas.
This seems to work, thanks! I have some values (in column C in the example) which are "NA" is there a way to skip them when doing the TAKE? So it would only TAKE the last 5 numeric values?
 
Upvote 0
This seems to work, thanks! I have some values (in column C in the example) which are "NA" is there a way to skip them when doing the TAKE? So it would only TAKE the last 5 numeric values?
I think I found a solution for anyone that's interested:
=AVERAGE(TAKE(FILTER(C2:C22,(A2:A22="john")*(B2:B22="design")*NOT(C2:C22="NA")),-2))
 
Upvote 0

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