+ Reply to Thread
Results 1 to 15 of 15

Sum data for each month

  1. #1
    Registered User
    Join Date
    08-12-2011
    Location
    NYC
    MS-Off Ver
    Excel 2003
    Posts
    7

    Question Sum data for each month

    Hello all,

    I have been attempting to solve this problem for about a week now using different combinations of functions but have not been able to produce what I wish.

    Let me begin with a description of my excel sheet:
    Sheet 2
    Column A: Dates in the following format: 2011-8-15
    These dates can repeat and or skip dates. They always increase in value however as you go down the column.

    Column B: numbers in decimal notation

    Sheet 1
    Sheet 1 is going to be used as a summary sheet which will show the totals for each month.

    I am having trouble in creating a function which will go down column a and figure out which rows in column b should be totaled in order to obtain the totals for each month. Please note that there is no predetermined number of rows of data for each month.

    I would love to hear some suggestions in how I could solve this problem. Plase note that I cannot use VBA to solve this problem as the excel file will be moved from mac to windows when needed.

    Thank you all for taking the time to read this.

  2. #2
    Valued Forum Contributor tlafferty's Avatar
    Join Date
    04-08-2011
    Location
    United States, Tacoma, WA
    MS-Off Ver
    Excel 2010, Excel 2013 Customer Preview
    Posts
    1,112

    Re: Help needed in creating a function to sum data for each month.

    I'd suggest using a pivot table to accomplish this. You could use sumif, but that makes your book "fragile" and constrains you to the layout you first choose when laying out your report. If you'd like an example of how it might look, please attach a sample workbook.
    If your question has been satisfactorily addressed, please consider marking it solved. Click the Thread Tools dropdown and select Mark thread as solved.
    Also, you might want to add to the user's reputation by clicking the star icon in the lower left corner of the post with the answer- it's why we do what we do...

    Thomas Lafferty
    Analyst/Programmer

  3. #3
    Registered User
    Join Date
    08-12-2011
    Location
    NYC
    MS-Off Ver
    Excel 2003
    Posts
    7

    Re: Help needed in creating a function to sum data for each month.

    I would attach my file but have no clue how to place an attachment.

  4. #4
    Registered User
    Join Date
    08-12-2011
    Location
    NYC
    MS-Off Ver
    Excel 2003
    Posts
    7

    Re: Help needed in creating a function to sum data for each month.

    Never mind, just found out.

    Here is my attachment
    Attached Files Attached Files

  5. #5
    Valued Forum Contributor tlafferty's Avatar
    Join Date
    04-08-2011
    Location
    United States, Tacoma, WA
    MS-Off Ver
    Excel 2010, Excel 2013 Customer Preview
    Posts
    1,112

    Re: Help needed in creating a function to sum data for each month.

    The attached has a pivot report. To produce one, click in the data you want to summarize, then click Insert=> pivot table=> new worksheet.

    Right click in your dates, then click group=> months.

    Note that it will reduce to a single month since that's all that your data includes.

    Regards,
    Tom
    Attached Files Attached Files

  6. #6
    Registered User
    Join Date
    08-12-2011
    Location
    NYC
    MS-Off Ver
    Excel 2003
    Posts
    7

    Re: Help needed in creating a function to sum data for each month.

    Is there any way to perform without the use of a pivot table? The users of this data are not computer savy and would like to just see a front page which would update itself as further data is entered in the future.

  7. #7
    Valued Forum Contributor tlafferty's Avatar
    Join Date
    04-08-2011
    Location
    United States, Tacoma, WA
    MS-Off Ver
    Excel 2010, Excel 2013 Customer Preview
    Posts
    1,112

    Re: Help needed in creating a function to sum data for each month.

    This will do the trick, but be aware that the formula only examines rows 2-30, so you'll want to expand that out for the future.

    Regards,
    Tom
    Attached Files Attached Files

  8. #8
    Registered User
    Join Date
    08-12-2011
    Location
    NYC
    MS-Off Ver
    Excel 2003
    Posts
    7

    Re: Help needed in creating a function to sum data for each month.

    Quote Originally Posted by tlafferty View Post
    This will do the trick, but be aware that the formula only examines rows 2-30, so you'll want to expand that out for the future.

    Regards,
    Tom
    That was exactly what I needed Tom. Thanks so much for your help.

    The function you provided me was:

    =SUMPRODUCT(--(MONTH(Entry!$A$2:$A$30)=MONTH(A2)*(YEAR(Entry!$A$2:$A$30)=YEAR(A2)))*(Entry!$B$2:$B$30))

    Can you help me understand:
    1. What does "--" do?
    2. Why can I not use "A:A" to define the entire column?

    Thank you again for your help Tom.

  9. #9
    Registered User
    Join Date
    08-12-2011
    Location
    NYC
    MS-Off Ver
    Excel 2003
    Posts
    7

    Re: Help needed in creating a function to sum data for each month.

    Tom,

    Looking at the code further, can you explain what it is doing exactly?

    I see that you are obtaining boolean values to check if the month and the year match the month and year of column A in the summary sheet but assuming that both conditions return a "1", what is the last bit of the code doing ($b$2:$b$30)?

    I figured out that -- converts true to 1 and false to 0

    Still not sure about why A:A can't be used.

    Thanks,
    Nick

  10. #10
    Valued Forum Contributor tlafferty's Avatar
    Join Date
    04-08-2011
    Location
    United States, Tacoma, WA
    MS-Off Ver
    Excel 2010, Excel 2013 Customer Preview
    Posts
    1,112

    Re: Sum data for each month

    You can definitely use A:A. One thing you may want to look into though if you will be using data that occupies thousands of rows is something along the lines of the SUMIF formula - it uses less memory than SUMPRODUCT. The -- forces Excel to treat the trues and falses as 1 and 0. There are some really good articles on the use of SUMPRODUCT, so you may want to consider googling it.

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

    Re: Sum data for each month

    Quote Originally Posted by tlafferty View Post
    You can definitely use A:A.
    I'm afraid the above is not entirely true.

    You can not use entire column references in Arrays/SUMPRODUCT prior to XL2007 - earlier versions will generate #NUM! errors.
    FWIW, you should never use entire column references with either Arrays or SUMPRODUCT, both approaches being inefficient when compared to "normal" functions.

    Quote Originally Posted by tlafferty
    One thing you may want to look into though if you will be using data that occupies thousands of rows is something along the lines of the SUMIF formula
    Agree with the above 100%.

    In this case given it's a simple month extraction I would suggest you combine two SUMIFs per calculation:

    Please Login or Register  to view this content.
    The above will be much more efficient than a SUMPRODUCT approach when working with large data sets.

    Regards:

    Please Login or Register  to view this content.
    in the above form the double unary is unnecessary given the arrays are being coerced latterly via multiplication... if you were to use SUMPRODUCT then for sake of robustness I confess I would look to use something along the lines of:

    Please Login or Register  to view this content.
    the above avoids explicit coercion of underlying values
    Last edited by DonkeyOte; 08-13-2011 at 03:25 AM. Reason: typo in narrative

  12. #12
    Registered User
    Join Date
    08-12-2011
    Location
    NYC
    MS-Off Ver
    Excel 2003
    Posts
    7

    Re: Sum data for each month

    Thank you Tom and DonkeyOte for all your help. Both solutions solve my problem for now and I understand what's going on with the code (I love that feeling).

  13. #13
    Registered User
    Join Date
    10-24-2014
    Location
    Kullu, India
    MS-Off Ver
    Office 2010
    Posts
    2

    Re: Sum data for each month

    Hello,

    Thanks a lot for these useful information.
    I am preparing a financial report worksheet which should produce monthly reports.
    I was wondering how to use a pivot table to add monthly data from several columns.
    In the example given in this thread there is the Entry Date and only one column of values.
    How could a pivot give a monthly sum or count or average for several columns of different values?
    Hope I am clear enough.
    I am a novice with Excel and with this forum as well ;-)

    Many thanks in advance

  14. #14
    Administrator FDibbins's Avatar
    Join Date
    12-29-2011
    Location
    Duncansville, PA USA
    MS-Off Ver
    Excel 7/10/13/16/365 (PC ver 2310)
    Posts
    52,926

    Re: Sum data for each month

    Hi, welcome to the forum

    Unfortunately your post does not comply with Rule 2 of our Forum RULES. Do not post a question in the thread of another member -- start your own thread.

    If you feel an existing thread is particularly relevant to your need, provide a link to the other thread in your new thread.

    Old threads are often only monitored by the original participants. New threads not only open you up to all possible participants again, they typically get faster response, too.
    1. Use code tags for VBA. [code] Your Code [/code] (or use the # button)
    2. If your question is resolved, mark it SOLVED using the thread tools
    3. Click on the star if you think someone helped you

    Regards
    Ford

  15. #15
    Registered User
    Join Date
    10-24-2014
    Location
    Kullu, India
    MS-Off Ver
    Office 2010
    Posts
    2

    Re: Sum data for each month

    Oh Sorry FDibbins,
    I didn't see that rule. I will start a new thread.
    Thanks for guiding me.

+ 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