Need To Modify An Existing Formula To Ignore Blank/Zero Cells When Calculating An Average

bobr31

New Member
Joined
Apr 1, 2015
Messages
6
Hi,

I am new to the forum and am looking for help modifying a formula. I am running a small golf league and need help modifying an array that I am using to calculate average scores.


The criteria is to take the last 6 scores, drop the 2 highest and then take the average of the 4 lowest then multiply the result by .95. Here's the formula I am using.

{=AVERAGE(SMALL(IF(C9:H9<>0,C9:H9),ROW(INDIRECT("1:"&MIN(4,COUNTIF(C9:H9,">0"))))))*0.95} The data is in a range from C22:P36

The spreadsheet calculates the correct average score when a golfer has not missed a week but fails when there are any zeros in the rows for missed weeks. Below, Bob's score calculates fine, but Jim's doesn't. I have been moving scores every week when someone misses, but that is a hassle.

Scores
Bob 45 48 55 45 43 42 49 50 55 52 43 46
Jim 55 49 0 53 0 55 51 50 0 43 0 50

The problem is that I am using a defined range that only looks back at the last 6 cells. I need the formula to keep looking back until it finds the last 6 cells excluding ones that are 0/blank and then get the average etc. I can't figure out how to get the formula to look back until it finds the lowest 4 of 6 scores that are <>0.

I have searched the forum but haven't found a thread with the answer. I was going to attach a sample spreadsheet, but learned that that is not possible.


Any help would be appreciated.

Many Thanks,

Bob
 

Excel Facts

Lock one reference in a formula
Need 1 part of a formula to always point to the same range? use $ signs: $V$2:$Z$99 will always point to V2:Z99, even after copying
Players with less than 6 scores would use the average of available scores until they reach 6 scores.

Why are the cells in such cases blank in your latest table then?

My formula would be (in B9 and copy across and down):

=0.95*AVERAGE(AGGREGATE(16,6,AGGREGATE(15,6,INDEX(2:2,N(IF(1,AGGREGATE(14,6,COLUMN($B2:B2)/ISNUMBER(1/$B2:B2),{1,2,3,4,5,6})))),{1,2,3,4}),{0,1,2,3}/3))

though I'm not sure how you want to treat any errors, nor, as I said, why you have those blanks I referred to in your table, which will not be such using the above.

Note that this solution assumes that the order of names in A2:A5 will be identical to that for those in A9:A12.

Regards
 
Upvote 0
Thanks. I was again forgetting the multiplier. Why don't we have an average in wk8 for Jim?

Your output exhibit of post #7 seems to suggest that the formula must be adapted to start in Wk6 (G9). If so:

G9, control+shift+enter, not just enter, copy across, and down:
Rich (BB code):

=IF(INDEX(FREQUENCY($B2:G2,0),2)>=6,
   AVERAGE(SMALL(IF(COLUMN($B2:G2)>=LARGE(IF(ISNUMBER(1/$B2:G2),
   COLUMN($B2:G2)),MIN(6,INDEX(FREQUENCY($B2:G2,0),2))),
   IF($B2:G2>0,$B2:G2)),{1,2,3,4}))*0.95,"")

Check out whether you would want 4 instead of the first occurrence of 6.
 
Upvote 0
I tried the one suggested by XOR LX (Thanks for the suggestion) but I had trouble adapting it to work as well in my master.

Aladin, I copied your formula into my master league spreadsheet and it appears to work GREAT! Thanks.

I tweaked it for 4 occurrences and that worked as well. Good suggestion. I don't fully understand it, but it works perfectly. What I want to do for new players is take their average scores up to 4 scores and then 4 of 5 and then 4 of 6 when they have 6+ scores. Will the formula do that with occurrence=4? Also, if I wanted to move to best 4 of 7 scores, how would I tweak the formula?

Thanks,

Bob
 
Upvote 0
I tried the one suggested by XOR LX (Thanks for the suggestion) but I had trouble adapting it to work as well in my master.

Aladin, I copied your formula into my master league spreadsheet and it appears to work GREAT! Thanks.

I tweaked it for 4 occurrences and that worked as well. Good suggestion. I don't fully understand it, but it works perfectly. What I want to do for new players is take their average scores up to 4 scores and then 4 of 5 and then 4 of 6 when they have 6+ scores. Will the formula do that with occurrence=4? Also, if I wanted to move to best 4 of 7 scores, how would I tweak the formula?

Thanks,

Bob

Let's define two parameters:

[1] LastN (last >0 scores)
[2] SmallestP (smallest subset < or equal to LastN)

Instead of {1,2,3,4}, we can encode variable SmallestP in the formula with: ROW(INDIRECT("1:"&SmallestP)).

That is:

Row\Col
A​
B​
C​
D​
E​
F​
G​
H​
I​
J​
K​
L​
1​
ScoresWk1Wk2Wk3Wk4Wk5Wk6Wk7Wk8Wk9Wk10Wk11
2​
Bob
45
48
55
45
43
42
49
50
55
52
43
3​
Jim
55
49
0
53
0
55
51
50
0
43
0
4​
Dan
53
0
55
51
50
0
43
0
5​
Jon
48
51
50
0
43
0
6​
7​
8​
AveragesWk1Wk2Wk3Wk4Wk5Wk6Wk7Wk8Wk9Wk10Wk11
9​
Bob
41.563
42.275
42.513
42.513
43.7
43.7
10​
Jim
50.35
49.4
48.213
48.213
45.838
45.838
11​
Dan
49.638
49.638
46.788
46.788
12​
Jon
45.6
45.6

G9, control+shift+enter, copy across, and down:
Rich (BB code):

=IF(INDEX(FREQUENCY($B2:G2,0),2)>=SmallestP,
   AVERAGE(SMALL(IF(COLUMN($B2:G2)>=LARGE(IF(ISNUMBER(1/$B2:G2),COLUMN($B2:G2)),
   MIN(LastN,INDEX(FREQUENCY($B2:G2,0),2))),IF($B2:G2>0,$B2:G2)),
   ROW(INDIRECT("1:"&SmallestP))))*0.95,"")

See the workbook that implements the set up: https://dl.dropboxusercontent.com/u...ater than 0 scores parameterized-version.xlsx
 
Upvote 0
Excellent. Thank You Aladin! Your solution works great and allowed me to run several scenarios to modify handicaps for this season and to rebuilt my entire league spreadsheet. I also learned a lot with your help. I used to be an excel geek, but haven't done much with it for about 10 years and this got me going again. Again, thanks for the help!
 
Upvote 0
Excellent. Thank You Aladin! Your solution works great and allowed me to run several scenarios to modify handicaps for this season and to rebuilt my entire league spreadsheet. I also learned a lot with your help. I used to be an excel geek, but haven't done much with it for about 10 years and this got me going again. Again, thanks for the help!

You are welcome. Great to restart. And thanks for the nice feedback.
 
Upvote 0

Forum statistics

Threads
1,221,444
Messages
6,159,914
Members
451,603
Latest member
SWahl

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