Averaging the total in a range of columns but don't count zeros in leading columns only

kristylee

New Member
Joined
Aug 28, 2006
Messages
21
This is a stumper - hoping someone has an idea. I need to calculate average hours worked by an employee in a quarter so I have all of the hours separated by each week in columns. I don't want to penalize new hires for the zero hours in the columns prior to when they were hired. But I do want to count the zeros if it is just a random week worked with no hours.

So in the example below, for Tom Smith, the first 2 weeks should not be counted into the average and for Jane Jones, all zeros should be counted since she had leading columns that had hours in them.

Anyone have a solution?


Tom Smith 0 0 8.5 27.75 9.25 17.25
Jane Jones 40.5 21.5 24 0 0 20
 

Excel Facts

Repeat Last Command
Pressing F4 adds dollar signs when editing a formula. When not editing, F4 repeats last command.
Hi,

Try this:-

I2 =IF(IFERROR(LOOKUP(0,--(B1:G1<>0),B1:G1),1)=0,SUM(B1:G1)/COUNTIF(B1:G1,"<>0"),AVERAGE(B1:G1))

ABCDEFGHI
1Tom Smith008.527.759.2517.2515.6875
2Jane Jones40.521.524002017.66667

<tbody>
</tbody>
 
Last edited:
Upvote 0
Try this
ARRAY formula (to be confirmed with Ctrl+Shift+Enter keys together) in I2 then drag down.

=SUM($B2:$G2)/(COLUMNS($B2:$G2)-MATCH(FALSE,$B2:$G2=0,0)+1)
 
Upvote 0
Seemed to work at first but then did some testing. If you change Tom Smith's column G to zero, it should count that last zero into the average but it doesn't. It should be average of 11.375 and it comes out as 15.16. Then, on Jane Jones I tried zeroing out columns C and D - the average should be 10.08 and it comes out as 30.25.
 
Upvote 0
Thanks for this but I tested it and something's not right. I changed Tom Smith's column G to zero (so that should figure into the average) and it gave me an average of 15.16 instead of 11.375. Then on Jane Jones I zeroed out 2 extra columns, C & D so average should be 10.08 and it comes out as 30.25. Help! :)
 
Upvote 0
Oops - I thought my first reply didn't go through so I'm sorry for the duplication. Couldn't figure out how to delete one of my replies. And that was in response to the first suggested solution. Re: the ARRAY one, not quite sure what that is... I have to play around a bit more.
 
Upvote 0
Hi,

Just Enter

I1 =SUM(B1:G1)/(COLUMNS(B1:G1)-MATCH(TRUE,INDEX(B1:G1<>0,),0)+1)


ABCDEFGHI
1Tom Smith008.527.759.25011.375
2Jane Jones000002020

<colgroup><col><col><col span="8"></colgroup><tbody>
</tbody>




BTW , kvsrinivasamurthy 's formula works fine .
 
Upvote 0

Forum statistics

Threads
1,214,922
Messages
6,122,281
Members
449,075
Latest member
staticfluids

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