Calculating average times in expandable table

JenniferMurphy

Well-known Member
Joined
Jul 23, 2011
Messages
1,396
Office Version
  1. 365
Platform
  1. Windows
I have a table with three sets of timestamps when some activity took place. I want to calculate the average of the time portion of the timestamps. I was able to get an array formula using the MOD function to work:

C/RDEF
6Sample ASample BSample C
703/01/19 09:07:4403/01/19 08:22:1403/01/19 09:22:25
803/02/19 08:41:1303/02/19 07:55:5203/02/19 09:16:33
903/04/19 09:10:2903/04/19 08:33:0203/04/19 09:09:34
1003/06/19 08:55:0003/06/19 08:11:2603/06/19 08:55:58
1103/07/19 09:12:0403/07/19 07:51:5603/07/19 09:29:34
129:01a8:10a9:14a

<tbody>
</tbody>

The formula in D12 is
Code:
{=AVERAGE(MOD(OFFSET(F6,1,0):OFFSET(F12,-1,0),1))}

The problem arises if there is missing data. The AVERAGE function will ignore empty cells, but the MOD function turns an empty cell into a zero, messing up the average.

C/RDEF
6Sample ASample BSample C
703/01/19 09:07:4403/01/19 08:22:1403/01/19 09:22:25
803/02/19 08:41:1303/02/19 07:55:5203/02/19 09:16:33
903/04/19 09:10:2903/04/19 09:09:34
1003/06/19 08:55:0003/06/19 08:11:2603/06/19 08:55:58
1103/07/19 09:12:0403/07/19 07:51:5603/07/19 09:29:34
129:01a6:28a9:14a

<tbody>
</tbody>

I tried putting a text string in that cell ('n/a or '--), but that gets a value error. Is there a way to get this work calculate the correct average of the non-empty cells?
 

Some videos you may like

Excel Facts

Difference between two dates
Secret function! Use =DATEDIF(A2,B2,"Y")&" years"&=DATEDIF(A2,B2,"YM")&" months"&=DATEDIF(A2,B2,"MD")&" days"

James006

Well-known Member
Joined
Apr 4, 2009
Messages
3,680
Hello,

If I understand correctly in cell D2 ... the formula works out the Average for Column F ... (which can be disturbing ...)

But the issue remains to avoid blank cells ...

You could test following:

Code:
=SUM(MOD(OFFSET(F6,1,0):OFFSET(F12,-1,0),1))/(COUNTA(OFFSET(F6,1,0):OFFSET(F12,-1,0)))

Hope this will help
 

JenniferMurphy

Well-known Member
Joined
Jul 23, 2011
Messages
1,396
Office Version
  1. 365
Platform
  1. Windows
Hello,

If I understand correctly in cell D2 ... the formula works out the Average for Column F ... (which can be disturbing ...)
Doh! :oops: I meant to say that formula was in F12, no D12. Sorry about that. :oops:

But the issue remains to avoid blank cells ...

You could test following:

Code:
=SUM(MOD(OFFSET(F6,1,0):OFFSET(F12,-1,0),1))/(COUNTA(OFFSET(F6,1,0):OFFSET(F12,-1,0)))

Hope this will help
Brilliant. It works perfectly, provided that I make it an array formula:
Code:
{=SUM(MOD(OFFSET(F6,1,0):OFFSET(F12,-1,0),1))/(COUNTA(OFFSET(F6,1,0):OFFSET(F12,-1,0)))}

Thank you! (y)
 

James006

Well-known Member
Joined
Apr 4, 2009
Messages
3,680
Glad you could fix your problem ...:wink:

Thanks a lot for the Beer ... !!! :)
 

Watch MrExcel Video

Forum statistics

Threads
1,122,914
Messages
5,598,840
Members
414,261
Latest member
KatieBsc

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
Top