How to create an excel formula that will average the 2 highest values that are separated by a 3 week difference in testing date

healthguy

New Member
Joined
Feb 24, 2020
Messages
2
Office Version
  1. 365
Platform
  1. Windows
Hey all,

I am looking for some help creating a formula to analyze some health data that I am looking at. I have a range of testing dates for a preventative screening and I am looking to calculate the average of the 2 highest values separated by 21 days. I will attach a sample spreadsheet of an example of what it looks like, but I want to be able to replicate this over multiple samples (around 200 or so different groupings of testings). I have played around using a few different functions, but have failed to put it all together. I appreciate help in any way possible. Thank you!


Days PostTest score
pt1
2​
1.5​
pt1
21​
2​
pt1
34​
3​
pt1
35​
2​
pt1
61​
5​
pt1
100​
6​
pt1
121​
2​
pt1
122​
7​
pt1
134​
8​
pt1
156​
1.4​
pt1
200​
5.3​
pt1
455​
3.4​
pt1
1133​
2​
 

Excel Facts

How can you automate Excel?
Press Alt+F11 from Windows Excel to open the Visual Basic for Applications (VBA) editor.
Could you please clarify your question...
Does "Days Post" refer to the number of days elapsed since a singular event, so that 2, 21, 34... days have a common zero time reference point?
And is the function to return the average of the two largest values separated by at least 21 days, or exactly 21 days? In your example, only two data points are separated by 21 days (100 and 121 days).
 
Upvote 0
Yes, sorry for the confusion. The is a 0 time point, which I should have included. That 0 point is the beginning and only sets the reference for the following points. The number of days then refer to the days since that 0 time point. The function should return the average of the 2 highest that are separated by at least 21 days. The overall goal is to find the person's peak function from the test, which is the average of the 2 largest values separated by at least 3 weeks (21 days). So the first step is finding the largest value from the test (8). Then from here, you need to find the second largest value separated by 21 or more days. The next highest value is 7, but since it is within 21 days, we have to exclude that. The next highest value is 6, which is more than 21 days - so we use this as the second value. The average between 6 and 8 give us the 7 we are looking for. That is how I would find it manually.
 
Upvote 0
Try:

Book1
ABCDE
1Days PostTest score
2pt121.57
3pt1212
4pt1343
5pt1352
6pt1615
7pt11006
8pt11212
9pt11227
10pt11348
11pt11561.4
12pt12005.3
13pt14553.4
14pt111332
Sheet3
Cell Formulas
RangeFormula
E2E2=AVERAGE(MAX(C2:C14),AGGREGATE(14,6,C2:C14/(ABS(B2:B14-LOOKUP(2,1/(C2:C14=MAX(C2:C14)),B2:B14))>=21),1))
 
Upvote 0
Well done, Eric. I struggled with finding a solution when there are two or more max values...yours handles that well. Thanks for sharing.
 
Upvote 0

Forum statistics

Threads
1,214,908
Messages
6,122,187
Members
449,072
Latest member
DW Draft

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