+ Reply to Thread
Results 1 to 13 of 13

Cumulative sum for weekly average hours over a month

  1. #1
    Registered User
    Join Date
    08-07-2008
    Location
    London
    Posts
    29

    Cumulative sum for weekly average hours over a month

    I have a column called "Weekly Working Hours" which totals the number of hours worked per week. The cell is filled in every Saturday.

    In the next column I have "Average Weekly Working Hours per Month" which needs to calculate the average number of weekly hours every four weeks, filled in every Saturday.

    Please see attached file. I am referring to columns J and K.

    A simple explanation of the solution would help too.

    Many thanks,

    Alis
    Attached Files Attached Files
    Last edited by alis88; 04-21-2009 at 06:32 AM.

  2. #2
    Forum Guru DonkeyOte's Avatar
    Join Date
    10-22-2008
    Location
    Northumberland, UK
    MS-Off Ver
    O365
    Posts
    21,531

    Re: Cumulative sum for weekly average hours over a month

    A few approaches, one would be to use an AVERAGE(IF array:

    K10: =AVERAGE(IF(($B$4:$B10>$B10-28)*(I$4:I10<>""),I$4:I10))
    committed with CTRL + SHIFT + ENTER
    copy to L10

    Be warned however that arrays are expensive performance wise...

    (the above assumes that you're not running XL2007, if you are you can make use of the AVERAGEIF which does not require CTRL + SHIFT + ENTER)
    Last edited by DonkeyOte; 04-21-2009 at 05:36 AM. Reason: operator should be > not >=

  3. #3
    Registered User
    Join Date
    08-07-2008
    Location
    London
    Posts
    29

    Re: Cumulative sum for weekly average hours over a month

    Hey DonkeyOte,

    Thanks for the reply- but I don't think that does what I want, does it?

    I don't think the averaging is working?

    Alis

  4. #4
    Forum Guru DonkeyOte's Avatar
    Join Date
    10-22-2008
    Location
    Northumberland, UK
    MS-Off Ver
    O365
    Posts
    21,531

    Re: Cumulative sum for weekly average hours over a month

    works for me but I did alter the operator from >= to > (@ 10.36am UK time) so if you used the example before then it would have been off slightly ...

    Are you entering as an array as advised (ie with CTRL + SHIFT + ENTER)

    It would be better to post a sample with more complete data such that multiple tests can be conducted.

  5. #5
    Registered User
    Join Date
    08-07-2008
    Location
    London
    Posts
    29

    Re: Cumulative sum for weekly average hours over a month

    I've got it.

    Thank you so much - you're a star!

    Alis xXx

  6. #6
    Registered User
    Join Date
    08-07-2008
    Location
    London
    Posts
    29

    Re: Cumulative sum for weekly average hours over a month

    Quote Originally Posted by DonkeyOte View Post
    A few approaches, one would be to use an AVERAGE(IF array:

    K10: =AVERAGE(IF(($B$4:$B10>$B10-28)*(I$4:I10<>""),I$4:I10))
    committed with CTRL + SHIFT + ENTER
    copy to L10

    Be warned however that arrays are expensive performance wise...

    (the above assumes that you're not running XL2007, if you are you can make use of the AVERAGEIF which does not require CTRL + SHIFT + ENTER)
    Sorry, one more question- how can I add an if="" then "" in that equation? I don't want the numbers to appear if the weekly data isn't there.

  7. #7
    Forum Guru DonkeyOte's Avatar
    Join Date
    10-22-2008
    Location
    Northumberland, UK
    MS-Off Ver
    O365
    Posts
    21,531

    Re: Cumulative sum for weekly average hours over a month

    Not clear I'm afraid - what governs no data - the current week only, ie:

    K10: =IF(AND($I10,$C10="Sat"),AVERAGE(IF(($B$4:$B10>$B10-28)*(I$4:I10<>""),I$4:I10)),"")
    committed with CTRL + SHIFT + ENTER

    The above will for ex. only execute the AVERAGE array if the sum of current weekly hours > 0 (as stipulated by I10 - itself the sum of G range)
    Last edited by DonkeyOte; 04-21-2009 at 06:48 AM. Reason: added SAT clause to reduce implementations of Array calc

  8. #8
    Registered User
    Join Date
    08-07-2008
    Location
    London
    Posts
    29

    Re: Cumulative sum for weekly average hours over a month

    I mean that I don't want the Average Weekly Working Hours per Month cell to be filled unless that week has been worked (see attached).
    Attached Files Attached Files

  9. #9
    Forum Guru DonkeyOte's Avatar
    Join Date
    10-22-2008
    Location
    Northumberland, UK
    MS-Off Ver
    O365
    Posts
    21,531

    Re: Cumulative sum for weekly average hours over a month

    see prior post

  10. #10
    Registered User
    Join Date
    08-07-2008
    Location
    London
    Posts
    29

    Re: Cumulative sum for weekly average hours over a month

    Now I am getting Value errors.

  11. #11
    Forum Guru DonkeyOte's Avatar
    Join Date
    10-22-2008
    Location
    Northumberland, UK
    MS-Off Ver
    O365
    Posts
    21,531

    Re: Cumulative sum for weekly average hours over a month

    ...Attached
    Attached Files Attached Files

  12. #12
    Registered User
    Join Date
    08-07-2008
    Location
    London
    Posts
    29

    Re: Cumulative sum for weekly average hours over a month

    You are really clever- I wish you all the best finding a job (perhaps to do with Excel?)

    Would you mind explaining your formula to me please?

    I can't thank you enough for your time.

  13. #13
    Forum Guru DonkeyOte's Avatar
    Join Date
    10-22-2008
    Location
    Northumberland, UK
    MS-Off Ver
    O365
    Posts
    21,531

    Re: Cumulative sum for weekly average hours over a month

    Flattery gets you everywhere...

    First off be sure to make use of Excel's Evaluate Formula tool... you can step through an entire formula to see how it is analysed (you can also use the formula bar and highlight a part of interest and press F9 to see how it evaulates)...

    Using example of K10:

    Please Login or Register  to view this content.
    The main bit is the AVERAGE Array... the outer IF is really just to say only conduct the AVERAGE Array if both I10 has a numerical value <> 0 and C10 is Sat... else return Null.

    So the AVERAGE...

    Please Login or Register  to view this content.
    Here we're creating a set of values to be Averaged... however we're using an IF to populate the set, we will only populate the set with the value in Column I if our IF test returns TRUE, in truth it will be hard to explain with the above given there's little data so let's simplify the example as follows...

    Consider range A1:B5

    Please Login or Register  to view this content.
    Let's say we want the Average of Column B but only where Column A is "a" and the value in Column B is > 0, our formula is thus:

    Please Login or Register  to view this content.
    Here we're populating our set of values based on the result of our IF... an IF as you know works like:

    Please Login or Register  to view this content.
    Notes:

    -- when the test in the IF is numerical we can make use of the fact that in XL terms only the value 0 equates to FALSE... every other value is TRUE.

    -- a Boolean TRUE/FALSE when coerced to an integer (via *, + etc...) becomes 1/0 respectively

    -- you have probably spotted that we don't set a FALSE argument in our Average Array - when not specified a Boolean of FALSE is automatically generated.

    So going back to our sample... the various elements are evaluated as so:

    Please Login or Register  to view this content.
    The 1st set of Booleans relate to whether or not A1:A5 = "a"
    The 2nd set of Booleans relate to whether or not B1:B5 > 0

    These 2 sets of Booleans are then coerced via multiplication such that the set can be condensed as follows:

    Please Login or Register  to view this content.
    The 1st set is the result of multiplying the 1st set of Booleans by the 2nd ,eg:

    Please Login or Register  to view this content.
    As discussed we know 0 equates to FALSE so in our IF we're going to exclude any values in the 2nd set where the first set = 0 ... so in reality the above becomes the below after the IF is evaluated:

    Please Login or Register  to view this content.
    the Average function will only use Numerical values in the set .. the Boolean FALSE values will be ignored so in essence we end up with:

    Please Login or Register  to view this content.
    Result being 3.

+ Reply to Thread

Thread Information

Users Browsing this Thread

There are currently 1 users browsing this thread. (0 members and 1 guests)

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts

Search Engine Friendly URLs by vBSEO 3.6.0 RC 1