+ Reply to Thread
Results 1 to 9 of 9

Need help writing formula to take 6-month average of data, pulling data using a code

  1. #1
    Registered User
    Join Date
    10-25-2022
    Location
    New York, NY
    MS-Off Ver
    Office 365
    Posts
    17

    Need help writing formula to take 6-month average of data, pulling data using a code

    Excel Help.xlsx

    Hello,

    I am trying to figure out how to write a formula that takes the average of the most recent 6 months of column I, "Cost per Unit," while pulling the data based on column A, "Meter Number."

    The goal is to be able to just edit the search criteria for different meter numbers to then pull the 6 month average without having to write separate formulas for each Meter's set of data.

    I realize my explanation might not be the best and apologize in advance for this but any help would be much appreciated!

    Sincerely,
    BoneyLit

  2. #2
    Forum Expert etaf's Avatar
    Join Date
    10-22-2004
    Location
    Wittering, West Sussex, UK
    MS-Off Ver
    365 (Mac OSX) (16.84 (24041420))
    Posts
    8,795

    Re: Need help writing formula to take 6-month average of data, pulling data using a code

    EDIT Note this goes back 6 months from the latest date for each meter and includes a 7 month - so beware on dates and use - just in case anyone else searching for a similar solution

    how about
    =AVERAGEIFS(I:I,A:A,L3,C:C,">="&DATE(YEAR(TODAY()),MONTH(TODAY())-6,DAY(TODAY())))

    BUT I get a DIV error on 1 of the meters - just looking into - no dates form 6 mths ago

    So just checking

    also using column C as the date - so not sure what you want last 6 months based on

    EDIT - UPDATE

    OK if you want 6mth from the lates date for that meter - how about
    =AVERAGEIFS(I:I,A:A,L3,C:C,">="&DATE(YEAR(MAXIFS(C:C,A:A,L3)),MONTH(MAXIFS(C:C,A:A,L3))-6,DAY(MAXIFS(C:C,A:A,L3))))

    we find the MAX date for column C for that meter and then take 6mths away
    Attached Files Attached Files
    Last edited by etaf; 10-25-2022 at 02:44 PM.
    Wayne
    if my assistance has helped, and only if you wish to , there is an "* Add Reputation" on the left hand side - you can add to my reputation here

    If you have a solution to your thread - Please mark your thread solved do the following: >
    Select Thread Tools-> Mark thread as Solved. To undo, select Thread Tools-> Mark thread as Unsolved.

  3. #3
    Forum Moderator Glenn Kennedy's Avatar
    Join Date
    07-08-2012
    Location
    Digital Nomad... occasionally based in Ireland.
    MS-Off Ver
    O365 (PC) V 2406
    Posts
    44,213

    Re: Need help writing formula to take 6-month average of data, pulling data using a code

    or:
    =UNIQUE(A2:A54)

    and

    =AVERAGE(TAKE(FILTER($D$2:$D$54,$A$2:$A$54=M23),6))

    assuming your O365 is up to date...
    Attached Files Attached Files
    Glenn




    None of us get paid for helping you... we do this for fun. So DON'T FORGET to say "Thank You" to all who have freely given some of their time to help YOU

  4. #4
    Registered User
    Join Date
    10-25-2022
    Location
    New York, NY
    MS-Off Ver
    Office 365
    Posts
    17

    Re: Need help writing formula to take 6-month average of data, pulling data using a code

    Hi Glenn,

    Thanks so much for your help! This works excellently. You are a gentlemen and a scholar and I appreciate you very much!

    Sincerely,
    BoneyLit

  5. #5
    Registered User
    Join Date
    10-25-2022
    Location
    New York, NY
    MS-Off Ver
    Office 365
    Posts
    17

    Re: Need help writing formula to take 6-month average of data, pulling data using a code

    Hi Etaf,

    Let me start out by saying if I spent the rest of my life trying to figure out that formula, I'd die a very disappointed man. That said, your formula is top notch and thanks so much for your help!

    Sincerely,
    BoneyLit

  6. #6
    Forum Moderator Glenn Kennedy's Avatar
    Join Date
    07-08-2012
    Location
    Digital Nomad... occasionally based in Ireland.
    MS-Off Ver
    O365 (PC) V 2406
    Posts
    44,213

    Re: Need help writing formula to take 6-month average of data, pulling data using a code

    You're welcome.



    It would be very nice if you were to just click the Add Reputation button at the foot of any of the posts of members who helped you reach a solution.

    Finally, if that takes care of your original question, please click on "Thread Tools" from the menu link (just above the first post in the thread) and mark this thread as SOLVED.

  7. #7
    Forum Expert etaf's Avatar
    Join Date
    10-22-2004
    Location
    Wittering, West Sussex, UK
    MS-Off Ver
    365 (Mac OSX) (16.84 (24041420))
    Posts
    8,795

    Re: Need help writing formula to take 6-month average of data, pulling data using a code

    you are welcome
    our formulas do give different results - i think
    which i have been looking into - also Leaning TAKE() - thanks glen

    ignore my formula - seems to be wrong - average for 1 meter, taking 7 readings and not six cannot work out why
    so use glens formula


    figured it out,
    column C for meter reading 7491408 has 7 readings
    starting with 2/2/22
    if you go back 6 months from the latest reading in column c
    which is 2/8/22 - that is 2/2/22 - so thats why i included that in the 6 months reading

    may not be what you want to include - but as i said , Glen is using the last 6 readings, where as i was using the last 6 months in column C which is the end of the period and not what you wanted

    needed to get to bottom of it - so anyone else searching the forum will know NOT to use my results
    Last edited by etaf; 10-25-2022 at 02:43 PM.

  8. #8
    Registered User
    Join Date
    10-25-2022
    Location
    New York, NY
    MS-Off Ver
    Office 365
    Posts
    17

    Re: Need help writing formula to take 6-month average of data, pulling data using a code

    Ok I didn't notice that but thanks for the extra info and for clearing that up! Your formula was still nice to me so I appreciate your help my friend. All the best!!!

    Sincerely,
    BoneyLit

  9. #9
    Forum Expert etaf's Avatar
    Join Date
    10-22-2004
    Location
    Wittering, West Sussex, UK
    MS-Off Ver
    365 (Mac OSX) (16.84 (24041420))
    Posts
    8,795

    Re: Need help writing formula to take 6-month average of data, pulling data using a code

    you are welcome

+ 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. Need formula to average daily data into month and year data
    By phantasm79 in forum Excel Formulas & Functions
    Replies: 13
    Last Post: 02-28-2014, 07:02 PM
  2. Pulling data from list into month/year table
    By EC11 in forum Excel Formulas & Functions
    Replies: 8
    Last Post: 09-17-2013, 02:45 PM
  3. Replies: 3
    Last Post: 03-26-2013, 09:07 PM
  4. Calculate average $/HR by pulling data from two workbooks
    By chouston in forum Excel Programming / VBA / Macros
    Replies: 1
    Last Post: 03-18-2013, 12:32 PM
  5. Pulling the average each month
    By Rwilliams_09 in forum Excel Formulas & Functions
    Replies: 7
    Last Post: 11-27-2012, 03:59 PM
  6. Pulling Data from a Specific Month
    By kjkb508 in forum Excel Formulas & Functions
    Replies: 5
    Last Post: 08-16-2012, 10:53 AM
  7. Pulling data only for the last date in the month
    By Reserv in forum Excel General
    Replies: 2
    Last Post: 04-25-2010, 05:51 AM
  8. pulling data into a month of worksheets, two tabs per day
    By lillian in forum Excel Programming / VBA / Macros
    Replies: 0
    Last Post: 10-25-2005, 08:05 PM

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