+ Reply to Thread
Results 1 to 22 of 22

Calculating Weekly Average from Irregular Data

  1. #1
    Registered User
    Join Date
    09-11-2009
    Location
    Washington, DC
    MS-Off Ver
    Excel 2003
    Posts
    28

    Calculating Weekly Average from Irregular Data

    ***I've bumped this and edited the first post to reflect the entire evolution of my thinking on this problem.***

    I'm working with a locksmith shop to develop a schedule for purchases of key blanks. Based on recent and future blank purchases, I want to produce a running average of the blanks that are consumed.

    Each model of key blank is purchased when its supply is exhausted. This happens at irregular intervals. Sometimes several models are purchased in an order and sometimes just one.

    A sample spreadsheet, with just two blank models and four dates, is included. (Excel 2007.)

    If I knew how to construct the formula, here's what it would do:

    1) count the days between the first and last purchase, for a given key blank

    2) sum all the purchases for that key blank, less the final purchase*

    3) divide the sum from step 2 by the number of days from step 1, for a daily average

    4) multiply the quotient from step 3 by 7 to get weekly usage (or 14 or 30)**

    Thanks for any help you can provide!

    *We omit the final purchase from the sum because without the next purchase date, we can't determine how quickly the new keys will be consumed. We use the date of final purchase as a proxy for when the second to last purchase was exhausted.

    **This average could be weekly, biweekly, or monthly, depending on the multiplier that we plug in here. I'm not clear yet on what would be most useful, but I'm starting with weekly.
    Attached Files Attached Files
    Last edited by non-pro; 03-08-2013 at 09:04 AM.

  2. #2
    Forum Expert Pepe Le Mokko's Avatar
    Join Date
    05-14-2009
    Location
    Belgium
    MS-Off Ver
    O365 v 2402
    Posts
    13,448

    Re: Calculating Weekly Average from Irregular Data

    Attach a sample workbook. Make sure there is just enough data to make it clear what is needed. Include BEFORE/AFTER sheets if needed to show the process you're trying to complete or automate. Remember to desensitize the data.

    Click on GO ADVANCED and use the paperclip icon to open the upload window.

    View Pic

  3. #3
    Registered User
    Join Date
    09-11-2009
    Location
    Washington, DC
    MS-Off Ver
    Excel 2003
    Posts
    28

    Re: Calculating Weekly Average from Irregular Data

    Here it is.
    Attached Files Attached Files

  4. #4
    Registered User
    Join Date
    12-11-2012
    Location
    cincinnati, ohio
    MS-Off Ver
    Excel 2010
    Posts
    43

    Re: Calculating Weekly Average from Irregular Data

    In K3, enter: SUM(B3:J3)/COUNTBLANK(B3:J3) ... you can copy this down into K4. If/when you need to add columns, just insert them in front of this column and the formula will automatically adjust.

  5. #5
    Registered User
    Join Date
    09-11-2009
    Location
    Washington, DC
    MS-Off Ver
    Excel 2003
    Posts
    28

    Re: Calculating Weekly Average from Irregular Data

    I think that solution assumes that each column represents a single week. If you'll look at the dates, you'll see that they span about seven months, in irregular intervals.

  6. #6
    Forum Expert Pepe Le Mokko's Avatar
    Join Date
    05-14-2009
    Location
    Belgium
    MS-Off Ver
    O365 v 2402
    Posts
    13,448

    Re: Calculating Weekly Average from Irregular Data

    What do you consider a week? A period of seven days starting on the first date? Form Sun to Sat, from Mon to Sun?

  7. #7
    Registered User
    Join Date
    09-11-2009
    Location
    Washington, DC
    MS-Off Ver
    Excel 2003
    Posts
    28

    Re: Calculating Weekly Average from Irregular Data

    I would consider a week to be seven days. I'd prefer to keep specific days out of the formula so that I have the option of swapping out seven days for 14 or 30, but this is a small point. If I HAD to choose a day of the week start counting on, it would be Monday.

  8. #8
    Registered User
    Join Date
    12-11-2012
    Location
    cincinnati, ohio
    MS-Off Ver
    Excel 2010
    Posts
    43

    Re: Calculating Weekly Average from Irregular Data

    The new solution takes into account all the weeks in a year. This only works assuming 2 things: you only use this WITHIN a year, not across years, and you have to maintain the date format dd/mm/yyyy. Solutions are in cells F3 and F4. As with my previous solution, just insert columns in front of this columns and the formulas will adjust with it.

    Hope this helps!

    Sample1.xlsx

  9. #9
    Registered User
    Join Date
    09-11-2009
    Location
    Washington, DC
    MS-Off Ver
    Excel 2003
    Posts
    28

    Re: Calculating Weekly Average from Irregular Data

    Getting much closer here.

    But when I put four consecutive Thursdays in four consecutive columns, with a value of 300 in each cell, it gives me a weekly average of 400.

  10. #10
    Registered User
    Join Date
    12-11-2012
    Location
    cincinnati, ohio
    MS-Off Ver
    Excel 2010
    Posts
    43

    Re: Calculating Weekly Average from Irregular Data

    That is actually correct, 4 consecutive Thursday's would only be 3 weeks... 1200/3 = 400. The formula can be changed to average over all the weeks in a year but, as it exists, it subtracts the weeknum of the first date from the weeknum of the last date; so, in your scenario, you would arrive at 3 weeks.

  11. #11
    Registered User
    Join Date
    09-11-2009
    Location
    Washington, DC
    MS-Off Ver
    Excel 2003
    Posts
    28

    Re: Calculating Weekly Average from Irregular Data

    Thanks for all of your efforts.

    My aim here is to calculate weekly consumption. Purchases on four consecutive Thursdays would likely be for four consecutive weeks, but we wouldn't actually know how quickly the fourth purchase would be used up until the next purchase was made. I see what you mean about them bookending a three-week stretch. Is there a way to construct the formula such that weekly usage is calculated based on all but the final purchase, but using the date of the final purchase as an end date? In other words, we'd be treating the purchases almost like right-censored spell data, since we don't know how long the materials last until they run out and we have to buy more.

    In time, I suppose that the variance from the actual weekly average in the current formula would approach zero. So maybe this isn't a big issue.

    More important at this point is that I be able to move the formula to column B so that my users never need to fiddle with adding columns in. I tried to do this myself but, alas, the formula was too much for me. Sorry I didn't think of this earlier.

    And again, thank you for your time.
    Last edited by non-pro; 03-05-2013 at 10:51 AM.

  12. #12
    Registered User
    Join Date
    09-11-2009
    Location
    Washington, DC
    MS-Off Ver
    Excel 2003
    Posts
    28

    Re: Calculating Weekly Average from Irregular Data

    bump?
    _____

  13. #13
    Registered User
    Join Date
    12-11-2012
    Location
    cincinnati, ohio
    MS-Off Ver
    Excel 2010
    Posts
    43

    Re: Calculating Weekly Average from Irregular Data

    The easiest way to add a week is just add 1 to the denominator... you'll see at the end of the new formulas there is a +1, that's all I did to add the week, that way you don't need a "place holder date" that doesn't get included at the end of your data. These new formulas review the data all the way out to column NA (you probably only need 52 columns, at most; so I built in 365). The averages have been moved to column B and will auto-update as "orders" are entered in the subsequent columns-- I changed the data for the first key to the example you provided in your last request.


    Sample1 (1).xlsx

  14. #14
    Registered User
    Join Date
    09-11-2009
    Location
    Washington, DC
    MS-Off Ver
    Excel 2003
    Posts
    28

    Re: Calculating Weekly Average from Irregular Data

    rodrignj,

    The changes you've made are great. And I hate to nitpick because you're helping me out of the goodness of your heart, but I think the puzzle is not yet solved. Adding the +1 resolved the problem for the scenario I mentioned earlier, but given different entries, the problem remains. For example, if I have two purchases of 300 keys on Feb 28 and March 21 (three weeks later), it provides me with an average of 150. In fact, 300 keys used over 3 weeks should average out to 100.

    I believe it's necessary to use the placeholder date rather than adding a week, as purchases are not usually made once a week. They could be made two days in a row and then two months apart from each other.

    If I knew how to construct the formula, here's what it would do:

    1) count the days between the first and last purchase, for a given key blank

    2) sum all the purchases for that key blank, less the final purchase

    3) divide the sum from step 2 by the number of days from step 1, for a daily average

    4) multiply the quotient from step 3 by 7 to get weekly usage (or 14 or 30)

    David
    Attached Files Attached Files
    Last edited by non-pro; 03-04-2013 at 01:40 PM.

  15. #15
    Registered User
    Join Date
    12-11-2012
    Location
    cincinnati, ohio
    MS-Off Ver
    Excel 2010
    Posts
    43

    Re: Calculating Weekly Average from Irregular Data

    First, I'll assume you meant March 21; with this assumption, the original formulas I gave you counted that as 3 weeks. You asked for the formula to treat that as 4 weeks, at 600 keys over 4 weeks that should be 150/week. Adding the 1 to the end is the exact same as adding a date, one week after the last recorded date, in the last column of your work. The formula is unconcerned with the frequency of purchases for the sake of determining your beginning and end dates. It uses your first date (now in C2), finds the last date, and subtracts your beginning date from it to find the number of weeks over which the purchases should be averaged. If you want that to be counted as 3 weeks, just remove the +1 from the end of the formula. If you are looking for something else entirely, let me know and we'll find an answer.

    That being said, if you're looking for a weekly average over a year, you should just be dividing by the week number of the very last date, instead of subtracting the week number of the first date from it.

  16. #16
    Registered User
    Join Date
    09-11-2009
    Location
    Washington, DC
    MS-Off Ver
    Excel 2003
    Posts
    28

    Re: Calculating Weekly Average from Irregular Data

    You're right about March 21 instead of March 31. I've corrected that in the original post.

    I think you're misunderstanding the way I want to measure this, and I apologize for having been unclear up to this point. Also, I'm probably having trouble grasping what you're saying.

    The assumption that I'm making is that new keys are purchased when we have used up all the old keys. And we can't use keys we've just purchased to measure how quickly we're using keys. We can only use purchased keys to measure key usage once they've been used up. We only know they've been used up because we had to buy new ones.

    In the first example, we bought 300 keys on each of four consecutive Mondays (which, yes, bookended three weeks). In the first week, we used 300 keys, so we had to buy 300 more the next Monday. Same thing in the second week and in the third week. On the fourth Monday (three weeks after the first purchase), we bought 300 more keys. This means we're using keys at a rate of 300 per week. It could take us 10 weeks to use up the keys we bought on the 4th Monday. We don't know until they're gone.

    In the second example, we bought 300 keys on a Monday. Three weeks later, we had to buy 300 more keys. That means that in the three weeks between these key purchases, we used 300 keys, or 100 keys per week.

    I think you might be hung up on the idea that keys are purchased on a weekly basis, which they are not. In testing your formulas, I've used consecutive weeks because it makes it easier to see that the model is or isn't working correctly. But we can't make the assumption that key purchases will be regular or that they'll be exhausted within a week.

    Thank you again, rodrignj, for your persistent help here.
    Last edited by non-pro; 03-04-2013 at 02:42 PM.

  17. #17
    Registered User
    Join Date
    12-11-2012
    Location
    cincinnati, ohio
    MS-Off Ver
    Excel 2010
    Posts
    43

    Re: Calculating Weekly Average from Irregular Data

    I recently got loaded up with a good amount of work so I am unable to finish this right now, I just wanted to quickly comment and point you in the right direction... the formula is meant to smooth the purchase of all keys into an average over the course of time indicated by the purchases, purchasing frequency is the least important factor/conclusion in/drawn from the formula. Because you initially indicated you were examining a year, I think the method of subtracting your beginning time from you end time is going to skew your data (it could be a lot, it could be not at all-- it depends when your beginning date is). I think you would be best served to just average it over the course of the YTD so that, by the end of the year, you have a good idea of key consumption for the entire year. That being said, I understand, now, your desire to not include the most recent purchase. I would recommend removing the +1 and trying to rework the formula to count to the end of the populated data and use all of the data -1. When I have more free time, I'll be sure to circle back around and see if this has been resolved; but you should be set on the right path with what you have now.

  18. #18
    Registered User
    Join Date
    09-11-2009
    Location
    Washington, DC
    MS-Off Ver
    Excel 2003
    Posts
    28

    Re: Calculating Weekly Average from Irregular Data

    Thank you, rodrignj. I really appreciate the help you've provided thus far. If it simplifies anything, I don't need this to be a yearly calculation. In fact, it would be better if the formula didn't cease to function at year's end. Good luck with all your work.

  19. #19
    Registered User
    Join Date
    09-11-2009
    Location
    Washington, DC
    MS-Off Ver
    Excel 2003
    Posts
    28

    Re: Calculating Weekly Average from Irregular Data

    bump, and thanks

  20. #20
    Registered User
    Join Date
    09-11-2009
    Location
    Washington, DC
    MS-Off Ver
    Excel 2003
    Posts
    28

    Re: Calculating Weekly Average from Irregular Data

    Not to be pushy, but one last attempt at a bump for this. Many thanks if you can help.

  21. #21
    Registered User
    Join Date
    06-08-2013
    Location
    Cardiff
    MS-Off Ver
    Excel Mac 2011
    Posts
    3

    Re: Calculating Weekly Average from Irregular Data

    I have a similar request...
    The attached sheet contains an abridged version of my gas energy consumption since 2006, obtained from gas bills from my suppliers.

    I want to be able to compare and analyse my usage over time. But the suppliers don't provide bill data in nice clean calendar month format. Most of this data is for split, uneven or irregular months (ie. Feb 23 2009 to Jun 3 2009; or even Nov 24 2010 to Jan 24 2011).

    What I want to do is peruse my data and assign relevant figures against *calendar months*. ie. Perhaps this is average daily kWh consumption?

    Any advances please?
    Thank-you.

  22. #22
    Forum Contributor arlu1201's Avatar
    Join Date
    09-09-2011
    Location
    Bangalore, India
    MS-Off Ver
    Excel 2003 & 2007
    Posts
    19,166

    Re: Calculating Weekly Average from Irregular Data

    robertandrews,

    Unfortunately you need to post your question in a new thread, it's against the forum rules to post a question in the thread of another user. If you create your own thread, any advice will be tailored to your situation so you should include a description of what you've done and are trying to do. Also, if you feel that this thread is particularly relevant to what you are trying to do, you can surely include a link to it in your new thread.
    If I have helped, Don't forget to add to my reputation (click on the star below the post)
    Don't forget to mark threads as "Solved" (Thread Tools->Mark thread as Solved)
    Use code tags when posting your VBA code: [code] Your code here [/code]

+ 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