+ Reply to Thread
Results 1 to 35 of 35

Need help averaging based on certain month and year.

  1. #1
    Registered User
    Join Date
    01-22-2013
    Location
    Texas
    MS-Off Ver
    Excel 2007, 2013
    Posts
    26

    Need help averaging based on certain month and year.

    So I have a workbook with multiple sheets and I need to average data based on the month and year in the adjacent cell. I have an array that I plug in to do monthly averaging, but I'm trying to go back and get older data. My date column (A) is setup month/day/year. The data that I want to average is in column (C). Also I need to keep the empty cells out of the formula.
    Last edited by phantasm79; 01-24-2017 at 01:05 PM. Reason: Solved

  2. #2
    Forum Expert Tony Valko's Avatar
    Join Date
    12-31-2011
    Location
    Pittsburgh
    MS-Off Ver
    2002, 2007:2013
    Posts
    18,890

    Re: Need help averaging based on certain month and year.

    Use cells to hold the date criteria.

    E2 = start date
    F2 = end date

    Then:

    =AVERAGEIFS(C2:C20,A2:A20,">="&E2,A2:A20,"<="&F2)

    Adjust the ranges to suit.
    Biff
    Microsoft MVP Excel
    Keep It Simple Stupid

    Let's Go Pens. We Want The Cup.

  3. #3
    Registered User
    Join Date
    01-22-2013
    Location
    Texas
    MS-Off Ver
    Excel 2007, 2013
    Posts
    26

    Re: Need help averaging based on certain month and year.

    I was looking for something that looked for the year and month in the formula so I could copy it down. I have 40 wells that I get a level reading from twice a month and some of the data goes back to the 60's. I'm trying to attach an example but it wont let me attach anything for some reason.

  4. #4
    Forum Expert Tony Valko's Avatar
    Join Date
    12-31-2011
    Location
    Pittsburgh
    MS-Off Ver
    2002, 2007:2013
    Posts
    18,890

    Re: Need help averaging based on certain month and year.

    Make sure it's a SMALL file.

    We don't need 1000's of rows and dozens of columns worth of data.

    20 rows and a few columns worth of data is plenty.

    To attach a file to your post...

    Click the Reply button to open the Reply Editor
    Click the Go Advanced button
    Scroll down until you see the Manage Attachments link and click that
    Click the Browse button and select your file
    Click the Open button
    Click the Upload button
    Click the Close Window button
    Click the Submit Reply button

  5. #5
    Registered User
    Join Date
    01-22-2013
    Location
    Texas
    MS-Off Ver
    Excel 2007, 2013
    Posts
    26

    Re: Need help averaging based on certain month and year.

    The attached file is the smallest example I have.
    Attached Files Attached Files

  6. #6
    Forum Expert Tony Valko's Avatar
    Join Date
    12-31-2011
    Location
    Pittsburgh
    MS-Off Ver
    2002, 2007:2013
    Posts
    18,890

    Re: Need help averaging based on certain month and year.

    OK, so what am I looking at here?

    Where is the data you want to average and where should the result(s) appear?

    This is why I asked for a SMALL sample file.

  7. #7
    Registered User
    Join Date
    01-22-2013
    Location
    Texas
    MS-Off Ver
    Excel 2007, 2013
    Posts
    26

    Re: Need help averaging based on certain month and year.

    Sorry it is a bit busy, but its the smallest one I have. The results are actually going to appear on another workbook, but for now lets say B2 on the next sheet. The data I want to reference is starts @ A6 (date column). The data I need to average starts @ C6 (Level column). I have about 40 of these sheets so what I'm trying to achieve is a column of years and row of months.

    Example: Say January 2011 I need to average the level (column C) for all 40 sheets for the corresponding date (column A).

  8. #8
    Forum Expert
    Join Date
    05-05-2015
    Location
    UK
    MS-Off Ver
    Microsoft Excel for Microsoft 365 MSO (Version 2402 Build 16.0.17328.20068) 64-bit
    Posts
    28,169

    Re: Need help averaging based on certain month and year.

    Try

    =SUM(SUMIF(INDIRECT("'"&Sheets&"'!A:A"),A6,INDIRECT("'"&Sheets&"'!C:C"))/SUM(COUNTIF(INDIRECT("'"&Sheets&"'!A:A"),A6)))

    where "Sheets" is a named range of ALL your 40 tabs.

    Enter with Ctrl+Shift+Enter

    Date in A6

  9. #9
    Forum Expert Tony Valko's Avatar
    Join Date
    12-31-2011
    Location
    Pittsburgh
    MS-Off Ver
    2002, 2007:2013
    Posts
    18,890

    Re: Need help averaging based on certain month and year.

    Quote Originally Posted by phantasm79 View Post
    I have about 40 of these sheets so what I'm trying to achieve is a column of years and row of months.
    You mean something like this:

    Data Range
    A
    B
    C
    D
    1
    Jan
    Feb
    Mar
    2
    2010
    3
    2011
    4
    2012


    And then the results would be the average across all 40 sheets?

    Doable but VERY complicated and calculation intensive.

  10. #10
    Registered User
    Join Date
    01-22-2013
    Location
    Texas
    MS-Off Ver
    Excel 2007, 2013
    Posts
    26

    Re: Need help averaging based on certain month and year.

    yup that's what the info would go into. complicated is why I came to the experts.

  11. #11
    Forum Expert Tony Valko's Avatar
    Join Date
    12-31-2011
    Location
    Pittsburgh
    MS-Off Ver
    2002, 2007:2013
    Posts
    18,890

    Re: Need help averaging based on certain month and year.

    Do the sheet names follow some sort of sequential naming pattern or are they just random?

  12. #12
    Forum Expert
    Join Date
    05-05-2015
    Location
    UK
    MS-Off Ver
    Microsoft Excel for Microsoft 365 MSO (Version 2402 Build 16.0.17328.20068) 64-bit
    Posts
    28,169

    Re: Need help averaging based on certain month and year.

    See the attached which is "sample" of what I think you require:

    3 sheets with dates in column A and data in C ("Template" generates data)

    Table in Summary is averages by MonTh and Year

    Formula in B2

    =SUM(SUMIFS(INDIRECT("'"&Sheets&"'!C:C"),INDIRECT("'"&Sheets&"'!A:A"),">=" & DATE($A2,MONTH(B$1),1),INDIRECT("'"&Sheets&"'!A:A"),"<=" & EOMONTH(DATE($A2,MONTH(B$1),1),0))/SUM(COUNTIFS(INDIRECT("'"&Sheets&"'!A:A"),">=" & DATE($A2,MONTH(B$1),1),INDIRECT("'"&Sheets&"'!A:A"),"<=" & EOMONTH(DATE($A2,MONTH(B$1),1),0))))

    Enter with Ctrl+Shift+Enter
    Attached Files Attached Files

  13. #13
    Registered User
    Join Date
    01-22-2013
    Location
    Texas
    MS-Off Ver
    Excel 2007, 2013
    Posts
    26

    Re: Need help averaging based on certain month and year.

    They all live in the same folder, but in different workbooks. The names are based on the well location so random.

  14. #14
    Registered User
    Join Date
    01-22-2013
    Location
    Texas
    MS-Off Ver
    Excel 2007, 2013
    Posts
    26

    Re: Need help averaging based on certain month and year.

    Quote Originally Posted by JohnTopley View Post
    See the attached which is "sample" of what I think you require:

    3 sheets with dates in column A and data in C ("Template" generates data)

    Table in Summary is averages by MonTh and Year

    Formula in B2

    =SUM(SUMIFS(INDIRECT("'"&Sheets&"'!C:C"),INDIRECT("'"&Sheets&"'!A:A"),">=" & DATE($A2,MONTH(B$1),1),INDIRECT("'"&Sheets&"'!A:A"),"<=" & EOMONTH(DATE($A2,MONTH(B$1),1),0))/SUM(COUNTIFS(INDIRECT("'"&Sheets&"'!A:A"),">=" & DATE($A2,MONTH(B$1),1),INDIRECT("'"&Sheets&"'!A:A"),"<=" & EOMONTH(DATE($A2,MONTH(B$1),1),0))))

    Enter with Ctrl+Shift+Enter
    I'm not following the filtered sheet references. Also there are data points I don't have on my workbook. Did you just make up some numbers?

  15. #15
    Forum Expert
    Join Date
    05-05-2015
    Location
    UK
    MS-Off Ver
    Microsoft Excel for Microsoft 365 MSO (Version 2402 Build 16.0.17328.20068) 64-bit
    Posts
    28,169

    Re: Need help averaging based on certain month and year.

    Yes the data is generated from random (RANDBETWEEN function): I was simply trying to establish if the format was what was required.

    So it calculates the data from a named list of tabs (your wells) and calculates the average by month for a given year.

  16. #16
    Registered User
    Join Date
    01-22-2013
    Location
    Texas
    MS-Off Ver
    Excel 2007, 2013
    Posts
    26

    Re: Need help averaging based on certain month and year.

    ok so with your method would I just point to the work sheet in place of "sheets" and indicate the range with c:c and a:a?

  17. #17
    Forum Expert
    Join Date
    05-05-2015
    Location
    UK
    MS-Off Ver
    Microsoft Excel for Microsoft 365 MSO (Version 2402 Build 16.0.17328.20068) 64-bit
    Posts
    28,169

    Re: Need help averaging based on certain month and year.

    In (under) "Sheets" you add the tab names (40 or so) ... changed the range in named range "Sheets" to be 40 sheets and change the starting range for the date : A6 in your sheet (?) whereas it was A2 in my example.

    As Tony pointed out, it will take some time to process 40 sheets.

    Perhaps test with 3 sheets (replacing Sheet1-3) [no change required to named range "Sheets"] so you can check the results: if these are OK add further entries into "Sheets"

  18. #18
    Registered User
    Join Date
    01-22-2013
    Location
    Texas
    MS-Off Ver
    Excel 2007, 2013
    Posts
    26

    Re: Need help averaging based on certain month and year.

    does it need to be in the same workbook?

  19. #19
    Forum Expert
    Join Date
    05-05-2015
    Location
    UK
    MS-Off Ver
    Microsoft Excel for Microsoft 365 MSO (Version 2402 Build 16.0.17328.20068) 64-bit
    Posts
    28,169

    Re: Need help averaging based on certain month and year.

    Yes: if there is a problem, post a file with 3 sheets (ZIP it if size is problem).

  20. #20
    Registered User
    Join Date
    01-22-2013
    Location
    Texas
    MS-Off Ver
    Excel 2007, 2013
    Posts
    26

    Re: Need help averaging based on certain month and year.

    No there isn't a problem, it works. Is there a way to make it exclude 0 and blank cells? Also could it be placed on its own workbook instead of where the data lives. The reason I ask is that twice a month I have to batch convert all my data to CSV for our website. I could just go and delete the extra files if it cant be done.

  21. #21
    Forum Expert
    Join Date
    05-05-2015
    Location
    UK
    MS-Off Ver
    Microsoft Excel for Microsoft 365 MSO (Version 2402 Build 16.0.17328.20068) 64-bit
    Posts
    28,169

    Re: Need help averaging based on certain month and year.

    To exclude 0s: based on my sample formula

    =SUM(SUMIFS(INDIRECT("'"&Sheets&"'!C:C"),INDIRECT("'"&Sheets&"'!C:C"),">=0",INDIRECT("'"&Sheets&"'!A:A"),">="&DATE($A2,MONTH(B$1),1),INDIRECT("'"&Sheets&"'!A:A"),"<="&EOMONTH(DATE($A2,MONTH(B$1),1),0))/SUM(COUNTIFS(INDIRECT("'"&Sheets&"'!C:C"),">=0",INDIRECT("'"&Sheets&"'!A:A"),">="&DATE($A2,MONTH(B$1),1),INDIRECT("'"&Sheets&"'!A:A"),"<="&EOMONTH(DATE($A2,MONTH(B$1),1),0))))

    Re being in a different workbook: INDIRECT only works with OPEN workbooks so you would to have your "data" workbook open.

    I'll need to try it and see.
    Last edited by JohnTopley; 01-23-2017 at 03:42 PM.

  22. #22
    Registered User
    Join Date
    01-22-2013
    Location
    Texas
    MS-Off Ver
    Excel 2007, 2013
    Posts
    26

    Re: Need help averaging based on certain month and year.

    Ok so the 0 isn't helping. What's happening is that occasionally I have missed checks and therefor have no data for some dates. I just leave these as a blank cell, but the date is there. It looks like the formula you've supplied is taking the 2 data points and averaging 1500 and 0 coming up with 750.

  23. #23
    Forum Expert
    Join Date
    05-05-2015
    Location
    UK
    MS-Off Ver
    Microsoft Excel for Microsoft 365 MSO (Version 2402 Build 16.0.17328.20068) 64-bit
    Posts
    28,169

    Re: Need help averaging based on certain month and year.

    If a value is 0 it is ignored: I tested this on my test file (sent to you), setting a cell to 0 or blank and it is not averaged.

    If still have it, set C10 in sheet1 to blank (or zero) and you will see the average change.

    If you look at the "validations" on the SUUMARY page and change the same value (B10) will get the same average and you will find it has ignored the blank.

    BUT my error (I changed from this originally)..


    =SUM(SUMIFS(INDIRECT("'"&Sheets&"'!C:C"),INDIRECT("'"&Sheets&"'!C:C"),">0",INDIRECT("'"&Sheets&"'!A:A"),">="&DATE($A2,MONTH(B$1),1),INDIRECT("'"&Sheets&"'!A:A"),"<="&EOMONTH(DATE($A2,MONTH(B$1),1),0))/SUM(COUNTIFS(INDIRECT("'"&Sheets&"'!C:C"),">0",INDIRECT("'"&Sheets&"'!A:A"),">="&DATE($A2,MONTH(B$1),1),INDIRECT("'"&Sheets&"'!A:A"),"<="&EOMONTH(DATE($A2,MONTH(B$1),1),0))))
    Last edited by JohnTopley; 01-23-2017 at 04:34 PM.

  24. #24
    Registered User
    Join Date
    01-22-2013
    Location
    Texas
    MS-Off Ver
    Excel 2007, 2013
    Posts
    26

    Re: Need help averaging based on certain month and year.

    that didn't fix mine. also I tried removing the date in C10 and it did nothing to the December 2016 value.

  25. #25
    Registered User
    Join Date
    01-22-2013
    Location
    Texas
    MS-Off Ver
    Excel 2007, 2013
    Posts
    26

    Re: Need help averaging based on certain month and year.

    I attached what I have so far. I'm just using the one that I have one well in.
    Attached Files Attached Files

  26. #26
    Forum Expert Tony Valko's Avatar
    Join Date
    12-31-2011
    Location
    Pittsburgh
    MS-Off Ver
    2002, 2007:2013
    Posts
    18,890

    Re: Need help averaging based on certain month and year.

    See if this file helps.
    Attached Files Attached Files

  27. #27
    Forum Expert
    Join Date
    05-05-2015
    Location
    UK
    MS-Off Ver
    Microsoft Excel for Microsoft 365 MSO (Version 2402 Build 16.0.17328.20068) 64-bit
    Posts
    28,169

    Re: Need help averaging based on certain month and year.

    You did not copy my formula: you entered your own version.

    The attached shows the results from my formula and Tony's.
    Attached Files Attached Files
    Last edited by JohnTopley; 01-24-2017 at 09:12 AM.

  28. #28
    Registered User
    Join Date
    01-22-2013
    Location
    Texas
    MS-Off Ver
    Excel 2007, 2013
    Posts
    26

    Re: Need help averaging based on certain month and year.

    Well I was pretty sure I copied what you put, but I guess not. Thought I only changed the range so I wouldn't be including the GPS coordinates at the top of column C, but I guess it doesn't matter since it doesn't have a corresponding date in A correct?

    So now my question is do you think Tony's or John's will calculate quicker when I put 40 of these together?

    Also have you made any progress on locating the data on a stand alone table?

    Also thanks a lot for ya'll help so far and thanks for the patience.

  29. #29
    Forum Expert Tony Valko's Avatar
    Join Date
    12-31-2011
    Location
    Pittsburgh
    MS-Off Ver
    2002, 2007:2013
    Posts
    18,890

    Re: Need help averaging based on certain month and year.

    Quote Originally Posted by phantasm79 View Post
    So now my question is do you think Tony's or John's will calculate quicker when I put 40 of these together?
    Did some testing using the timer code found here:

    http://msdn.microsoft.com/en-us/library/aa730921.aspx

    I tested just the single formula for Dec 2016. Here are the test results. Results are times in seconds.

    Data Range
    N
    O
    P
    Q
    R
    S
    T
    U
    16
    Test1
    Test2
    Test3
    Test4
    Test5
    Test6
    Average
    17
    JohnTopley
    0.00700
    0.00698
    0.00698
    0.00972
    0.00712
    0.00699
    0.00747
    18
    Tony Valko
    0.00078
    0.00120
    0.00079
    0.00079
    0.00078
    0.00077
    0.00085


    That's just for 1 sheet. For 40 sheets this will be slow to calculate.

  30. #30
    Forum Expert
    Join Date
    05-05-2015
    Location
    UK
    MS-Off Ver
    Microsoft Excel for Microsoft 365 MSO (Version 2402 Build 16.0.17328.20068) 64-bit
    Posts
    28,169

    Re: Need help averaging based on certain month and year.

    No: I haven't done any further work re results in separate workbook..

    Perhaps Tony might advise on this as his formula is by far the faster.

  31. #31
    Registered User
    Join Date
    01-22-2013
    Location
    Texas
    MS-Off Ver
    Excel 2007, 2013
    Posts
    26

    Re: Need help averaging based on certain month and year.

    Again thanks for the help and patience, if you think of a way or chat with someone that can show me how to put the formulas on a separate workbook send them my way. Just seems like the path could be put into the formula so the output data can live in a different workbook. It might take forever to calculate, but I'm cool with that. I have one that takes 3 minutes.

  32. #32
    Forum Expert
    Join Date
    05-05-2015
    Location
    UK
    MS-Off Ver
    Microsoft Excel for Microsoft 365 MSO (Version 2402 Build 16.0.17328.20068) 64-bit
    Posts
    28,169

    Re: Need help averaging based on certain month and year.

    Try

    =IFERROR(SUM(SUMIFS(INDIRECT("'[Upper Trinity Graphs.xlsx]"&Sheets&"'!C:C"),INDIRECT("'[Upper Trinity Graphs.xlsx]"&Sheets&"'!C:C"),">0",INDIRECT("'[Upper Trinity Graphs.xlsx]"&Sheets&"'!A:A"),">="&DATE($A2,MONTH(B$1),1),INDIRECT("'[Upper Trinity Graphs.xlsx]"&Sheets&"'!A:A"),"<="&EOMONTH(DATE($A2,MONTH(B$1),1),0))/SUM(COUNTIFS(INDIRECT("'[Upper Trinity Graphs.xlsx]"&Sheets&"'!C:C"),">0",INDIRECT("'[Upper Trinity Graphs.xlsx]"&Sheets&"'!A:A"),">="&DATE($A2,MONTH(B$1),1),INDIRECT("'[Upper Trinity Graphs.xlsx]"&Sheets&"'!A:A"),"<="&EOMONTH(DATE($A2,MONTH(B$1),1),0)))),"")

    Insert highlighted into INDIRECT formulae


    OR

    =IFERROR(SUM(SUMIFS(INDIRECT("'[" & FileName & "]"&Sheets&"'!C:C"),INDIRECT("'[" & FileName & "]"&Sheets&"'!C:C"),">0",INDIRECT("'[" & FileName & "]"&Sheets&"'!A:A"),">="&DATE($A2,MONTH(B$1),1),INDIRECT("'[" & FileName & "]"&Sheets&"'!A:A"),"<="&EOMONTH(DATE($A2,MONTH(B$1),1),0))/SUM(COUNTIFS(INDIRECT("'[" & FileName & "]"&Sheets&"'!C:C"),">0",INDIRECT("'[" & FileName & "]"&Sheets&"'!A:A"),">="&DATE($A2,MONTH(B$1),1),INDIRECT("'[" & FileName & "]"&Sheets&"'!A:A"),"<="&EOMONTH(DATE($A2,MONTH(B$1),1),0)))),"")

    Where FileName is named range containing name of your date file e.g.Upper Trinity Graphs.xlsx
    Last edited by JohnTopley; 01-24-2017 at 03:20 PM.

  33. #33
    Registered User
    Join Date
    01-22-2013
    Location
    Texas
    MS-Off Ver
    Excel 2007, 2013
    Posts
    26

    Re: Need help averaging based on certain month and year.

    Where does it pull the sheets from? My &sheets& don't light up when I inspect the formula.

  34. #34
    Forum Expert
    Join Date
    05-05-2015
    Location
    UK
    MS-Off Ver
    Microsoft Excel for Microsoft 365 MSO (Version 2402 Build 16.0.17328.20068) 64-bit
    Posts
    28,169

    Re: Need help averaging based on certain month and year.

    "Sheets" is named range with sheet names

  35. #35
    Registered User
    Join Date
    01-22-2013
    Location
    Texas
    MS-Off Ver
    Excel 2007, 2013
    Posts
    26

    Re: Need help averaging based on certain month and year.

    You mean make a sheet list in the new workbook?

+ 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. start month, end month based on year and period
    By stephme55 in forum Excel General
    Replies: 4
    Last Post: 09-06-2016, 04:56 PM
  2. Days of the month and week based on name month/year
    By RickMcc in forum Excel Programming / VBA / Macros
    Replies: 7
    Last Post: 09-01-2016, 03:22 PM
  3. Running Totals from 24 hours to month, month to year without year decreasing
    By Safetyintern in forum Excel Formulas & Functions
    Replies: 2
    Last Post: 05-20-2015, 01:13 PM
  4. [SOLVED] Averaging Multiple columns based on Weeknum compared to Month
    By zdonner in forum Excel Formulas & Functions
    Replies: 2
    Last Post: 08-14-2014, 03:43 PM
  5. Change year but keep the month the same based on current year
    By Jamon Fries in forum Excel Formulas & Functions
    Replies: 4
    Last Post: 03-11-2014, 05:29 PM
  6. Return value of the last week of the month based on the year and month
    By stevekho2 in forum Excel Formulas & Functions
    Replies: 7
    Last Post: 09-14-2013, 11:04 AM
  7. If Column A Month and Year = ColumnB Todays Month and Year then send email
    By HACCStaff in forum Excel Formulas & Functions
    Replies: 3
    Last Post: 04-15-2013, 12:47 AM

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