+ Reply to Thread
Results 1 to 11 of 11

Average Last 7 Days by Weekday/Weekend

  1. #1
    Registered User
    Join Date
    07-18-2013
    Location
    United States
    MS-Off Ver
    Excel 2010
    Posts
    6

    Average Last 7 Days by Weekday/Weekend

    Hi,

    I am trying to create a formula that will automatically average data from the last 7 days in a table based on whether or not it's a weekday or weekend. I have to update this on a weekly basis and want the template to pull the last 7 days without having to manually change the table array which is why I'm not just using an averageifs tied to the value in column a. I've attached an example file on what I'm working with.

    I have tried a variation of different averageifs and offsets and while I can get some formulas to work, I cannot think of a way automatically select the last 7 days and get it to average based on whether or not it's a weekday or weekend. Essentially, I want the formula =average(offset(c1,counta(c1:c31)-7,0,7) to average based on weekdays vs weekends.

    Any input would be greatly appreciated and thank you in advance!!
    Attached Files Attached Files
    Last edited by cleone1387; 10-22-2014 at 07:18 PM.

  2. #2
    Forum Expert Ron Coderre's Avatar
    Join Date
    03-22-2005
    Location
    Boston, Massachusetts
    MS-Off Ver
    2013, 2016, O365
    Posts
    6,996

    Re: Average Last 7 Days by Weekday/Weekend

    Using your posted workbook and assuming all days of the month are listed once,here's one way:
    This regular formula returns the average of the last 7 Col_C non-blank values where the corresponding Col_B date is a weekday
    Please Login or Register  to view this content.
    For your data, that formula returns: 17,309
    (13154;21354;45641;13154;1052;13654;13154)/7

    Is that something you can work with?
    Ron
    Former Microsoft MVP - Excel (2006 - 2015)
    Click here to see the Forum Rules

  3. #3
    Registered User
    Join Date
    07-18-2013
    Location
    United States
    MS-Off Ver
    Excel 2010
    Posts
    6

    Re: Average Last 7 Days by Weekday/Weekend

    Hi Ron,

    Thanks for your reply! I should clarify I'm not looking for an average of the last 7 weekdays, rather of the last 7 days an average for the 5 weekdays and the 2 weekend days. So using the data from the posted workbook essentially two formulas that yield:
    • Weekday:$17,331 (45641,13154,1052,13654,13154)/5
    • Weekend:$33,498 (21354,45641)/2

    The simple solution is to use an averageifs and a ">5" and "<6" however I don't know how to get it to auto populate based on the bottom 7 cells.
    Last edited by cleone1387; 10-22-2014 at 08:34 PM.

  4. #4
    Forum Expert Ron Coderre's Avatar
    Join Date
    03-22-2005
    Location
    Boston, Massachusetts
    MS-Off Ver
    2013, 2016, O365
    Posts
    6,996

    Re: Average Last 7 Days by Weekday/Weekend

    Last 5 weekdays:
    Please Login or Register  to view this content.
    Last 2 weekend days:
    Please Login or Register  to view this content.
    Does that help?

  5. #5
    Registered User
    Join Date
    07-18-2013
    Location
    United States
    MS-Off Ver
    Excel 2010
    Posts
    6

    Re: Average Last 7 Days by Weekday/Weekend

    Hi Ron,

    Thanks for another quick reply, I truly appreciate it! The formulas definitely work for the mock spreadsheet I originally posted, but when I try to apply to my actual model I get an "#N/A" error. Is there a reason this formula wouldn't work on a different spreadsheet so long as I align the table arrays? I'm not entirely sure what this formula is telling excel to do so trying to modify isn't working out for me.

    I've attached the actual template I'm working with, just changed the numbers, and was hoping you could let me know what you think could be the issue? On the "Weekday-end average Temp" file, I've highlighted cells k34 and k35 in yellow as these are your formulas with adjusted table arrays but showing the "#N/A" error.
    Attached Files Attached Files

  6. #6
    Forum Expert Ron Coderre's Avatar
    Join Date
    03-22-2005
    Location
    Boston, Massachusetts
    MS-Off Ver
    2013, 2016, O365
    Posts
    6,996

    Re: Average Last 7 Days by Weekday/Weekend

    Well, that's a different scenario. It appears that you add dates as you add data, so you have blank cells below the data range. The previous formula I posted gets tripped up by those blank cells because the FREQUENCY function is returning fewer values than there are rows referenced in I2:I32.

    Try these regular formulas:

    Weekend average
    Please Login or Register  to view this content.
    Weekday average
    Please Login or Register  to view this content.
    In your example...
    Weekend average = 13,399
    Weekday average = 43,327.5

    Does that help?

  7. #7
    Registered User
    Join Date
    07-18-2013
    Location
    United States
    MS-Off Ver
    Excel 2010
    Posts
    6

    Re: Average Last 7 Days by Weekday/Weekend

    Hi Ron,

    The formula seems to be working in that I don't get an error, however, I don't think those are the right totals. When I manually average the last 5 workdays I get 17,331 and 33,498 for last 2 weekend days.

    Any thoughts? Thanks again for all the help with this.

  8. #8
    Forum Expert Ron Coderre's Avatar
    Join Date
    03-22-2005
    Location
    Boston, Massachusetts
    MS-Off Ver
    2013, 2016, O365
    Posts
    6,996

    Re: Average Last 7 Days by Weekday/Weekend

    Yikes...I merged portions of the two formulas...and even mis-labeled them in my post.

    These are the corrected formulas:
    Weekend average
    Please Login or Register  to view this content.
    Resolves to: 33,497.50

    Weekday average:
    Please Login or Register  to view this content.
    Resolves to: 17,331.00

    Better?

  9. #9
    Registered User
    Join Date
    07-18-2013
    Location
    United States
    MS-Off Ver
    Excel 2010
    Posts
    6

    Re: Average Last 7 Days by Weekday/Weekend

    That's it! This is perfect, thanks so much, Ron. I truly appreciate your help on this.

    If possible, can you explain what this formula is telling Excel to do - I am not familiar with the Large or Index formulas.

  10. #10
    Forum Expert Ron Coderre's Avatar
    Join Date
    03-22-2005
    Location
    Boston, Massachusetts
    MS-Off Ver
    2013, 2016, O365
    Posts
    6,996

    Re: Average Last 7 Days by Weekday/Weekend

    I'll use the weekend formula
    =SUMPRODUCT(($B$2:$B$32=LARGE(INDEX((WEEKDAY($B$2:$B$32,2)>5)*$B$2:$B$32,0),{1,2}))*$I$2:$I$32)/2

    The LARGE function returns the 1st, 2nd, or whatever largest item in a list.
    If A1:A5 contains this list
    10
    2
    6
    1
    4

    =LARGE(A1:A5,3) returns: 4 (the 3rd largest value)

    However, if you entered this in a cell:
    =LARGE(A1:A5,{1,2,3})

    the result would be an array of the top 3 largest values.
    You can check by:
    • select the cell containing that formula
    • press F2
    • press F9
    the result in the formula bar with be: {10,6,4}
    • Press ESC to restore the formula

    The INDEX function typically references ranges as if the range was the entire spreadsheet.
    This formula:
    =INDEX(C10:E15,2,3)
    would reference the 2nd row, 3rd column of C10:E15

    However, when used like I did in the formula I posted (with a zero as the last parameter), it forces Excel to treat the referenced range as an array...eliminating the need to create an array formula (which you'd complete by holding down CTRL and SHIFT when you press ENTER, instead of just pressing ENTER)

    So this section of the formula:
    INDEX((WEEKDAY($B$2:$B$32,2)>5)*$B$2:$B$32,0)

    tests if the weekday of each cell in $B$2:$B$32 is greater than 5 (and therefore a Saturday or a Sunday)
    If Yes...the result is TRUE...which Excel sees as 1.
    If No....the result is FALST..which Excel sees as 0.

    When that array of 1's and 0's is multiplied times the dates in $B$2:$B$32,
    the result is a series of weekend date serial numbers and zeros.

    The LARGE function returns the top 1 and 2 values.
    The SUMPRODUCT function sums those top 2 values.
    That sum is then divided by 2 to calculate the average.

    I hope that helps.

  11. #11
    Registered User
    Join Date
    07-18-2013
    Location
    United States
    MS-Off Ver
    Excel 2010
    Posts
    6

    Re: Average Last 7 Days by Weekday/Weekend

    Hi Ron,

    This definitely helps, it's fantastic! I really can't thank you enough for helping with the formulas and then providing an explanation on how they work.

    Thanks again,

    Chris

+ Reply to Thread

Thread Information

Users Browsing this Thread

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

Similar Threads

  1. [SOLVED] Calculate Overtime Weekday different from Weekend
    By Lg101 in forum Excel Formulas & Functions
    Replies: 3
    Last Post: 08-07-2014, 04:41 PM
  2. [SOLVED] COUNTIFS dependent on date being on weekday or weekend
    By weldo in forum Excel Formulas & Functions
    Replies: 3
    Last Post: 03-26-2014, 04:09 PM
  3. [SOLVED] help please to identify and display 'WEEKDAY' or 'WEEKEND'
    By vin1602 in forum Excel Formulas & Functions
    Replies: 7
    Last Post: 09-06-2013, 06:30 AM
  4. [SOLVED] Extracting data depending on whether a date is a weekday or weekend
    By weldo in forum Excel Formulas & Functions
    Replies: 2
    Last Post: 09-19-2012, 11:24 AM
  5. Replies: 2
    Last Post: 12-09-2011, 07:11 AM

Tags for this Thread

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