Need to calculate Average of first 5 non-zero cells in a ROW

paulgunther

New Member
Joined
Oct 30, 2019
Messages
31
Office Version
  1. 365
Platform
  1. Windows
In this example, each score is entered for only the players that played this week leaving lots of blank cells. A new column is added each week between Column D(Hidden) and E. I did this so the arrays in formulas will automatically update when a column is inserted inside the array.

In Column B, I need to calculate a handicap based on only the last 5 rounds played. The “Handicap” is the difference between Par (54) and the average.
EXAMPLE: Last 5 rounds are 50,46,49,50,60 The Average = 51 and the Handicap = +3 (54-Average)
I’ve tried to do an augmented version of Excel Magic Trick 677 to no avail. Thanks in advance!


Book1
ABCEFGHIJKLMNOP
1Rounds
2PlayedHCP10/27/1910/20/1910/13/1910/6/199/29/199/22/199/15/199/8/199/1/198/25/198/18/198/11/19
36-5Player 1665860565558
46-5Player 2636155586061
56-3Player 3546359545755
68-5Player 45461626157565167
782Player 55253565247545850
89-3Player 6605457565857576457
9102Player 751515453515253475655
Scores
 
No doubt there's a better way, but this was quick:

Book4
ABCDEFGH
1
231
3Today's Par545454
4RoundsHCPPlayer5/31/20205/24/20205/17/2020
56-10Player 1
664Player 2
70NoHCPPlayer 3
83-46Player 481
990Player 5
10112Player 6535053
1192Player 7
122NoHCPPlayer 8
131NoHCPPlayer 9
147-7Player 106060
156#NUM!Player 1150
160NoHCPPlayer 12
170NoHCPPlayer 13
182NoHCPPlayer 1470
193-23Player 15708179
201NoHCPPlayer 16
218-4Player 1758
228-2Player 18565658
231NoHCPPlayer 19
Sheet6
Cell Formulas
RangeFormula
F4:H4F4=G4+7
B5B5=COUNTIF(INDEX(5:5,6):INDEX(5:5,$A$2),">0")
C5:C23C5=IF(B5<3,"NoHCP",(IF(B5<5,ROUND(AVERAGE(IF(INDEX(5:5,6):INDEX(5:5,$A$2)<>"",INDEX(5:5,6):INDEX(5:5,$A$2)-INDEX($3:$3,6):INDEX($3:$3,$A$2))),0),ROUND(AVERAGE(SMALL(IF((INDEX(5:5,6):INDEX(5:5,$A$2)<>"")*(COLUMN(INDEX(5:5,6):INDEX(5:5,$A$2))<=SMALL(IF(INDEX(5:5,6):INDEX(5:5,$A$2)<>"",COLUMN(INDEX(5:5,6):INDEX(5:5,$A$2))),5)),INDEX(5:5,6):INDEX(5:5,$A$2)-INDEX($3:$3,6):INDEX($3:$3,$A$2)),{2,3,4})),0)))*(-1))
B6:B23B6=COUNTIF(E6:HR6,">0")
Press CTRL+SHIFT+ENTER to enter array formulas surrounded with curly braces.


It just replaces E5:CW5 with INDEX(5:5,6):INDEX(5:5,$A$2) and E$3:CW$3 with INDEX($3:$3,6):INDEX($3:$3,$A$2) everywhere in the formulas, where 6 is the starting column and $A$2 (31) is the ending column (31-6+1 = 26 weeks).

If you define 2 Names as shown, you can shorten the formula a lot, as well as making it more readable.

Book4
ABCDEFGH
1
231
3Today's Par545454
4RoundsHCPPlayer5/31/20205/24/20205/17/2020
56-10Player 1
664Player 2
70NoHCPPlayer 3
83-46Player 481
990Player 5
10112Player 6535053
1192Player 7
122NoHCPPlayer 8
131NoHCPPlayer 9
147-7Player 106060
156#NUM!Player 1150
160NoHCPPlayer 12
170NoHCPPlayer 13
182NoHCPPlayer 1470
193-23Player 15708179
201NoHCPPlayer 16
218-4Player 1758
228-2Player 18565658
231NoHCPPlayer 19
Sheet6
Cell Formulas
RangeFormula
F4:H4F4=G4+7
B5B5=COUNTIF(RowRange,">0")
C5:C23C5=IF(B5<3,"NoHCP",(IF(B5<5,ROUND(AVERAGE(IF(RowRange<>"",RowRange-TopRow)),0),ROUND(AVERAGE(SMALL(IF((RowRange<>"")*(COLUMN(RowRange)<=SMALL(IF(RowRange<>"",COLUMN(RowRange)),5)),RowRange-TopRow),{2,3,4})),0)))*(-1))
B6:B23B6=COUNTIF(E6:HR6,">0")
Press CTRL+SHIFT+ENTER to enter array formulas surrounded with curly braces.
Named Ranges
NameRefers ToCells
RowRange=INDEX(Sheet6!$1:$999,ROW(),6):INDEX(Sheet6!$1:$999,ROW(),Sheet6!$A$2)B5, C5:C23
TopRow=INDEX(Sheet6!$1:$999,3,6):INDEX(Sheet6!$1:$999,3,Sheet6!$A$2)B5, C5:C23



Sheet6 was where I tested, change yours to match your workbook. You define Names on the Formula tab.
 
Upvote 0

Excel Facts

Can a formula spear through sheets?
Use =SUM(January:December!E7) to sum E7 on all of the sheets from January through December
So if I insert a column each week at F, will this redefine the Named Ranges making them larger than the 26 weeks I'm looking for?
 
Upvote 0
No, the column numbers are fixed, not dynamic. They will always stay 6-31. If we used a range of F:Z, and you added a column before F, it would redefine the range. But not when I hardcoded the columns as numbers, not letters.
 
Upvote 0

Forum statistics

Threads
1,224,812
Messages
6,181,104
Members
453,021
Latest member
Justyna P

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