+ Reply to Thread
Results 1 to 10 of 10

Sumif and Averages?

Hybrid View

byepeeps Sumif and Averages? 04-14-2011, 07:19 PM
TMS Re: Sumif and Averages? 04-14-2011, 07:26 PM
byepeeps Re: Sumif and Averages? 04-14-2011, 08:10 PM
TMS Re: Sumif and Averages? 04-15-2011, 02:51 AM
daddylonglegs Re: Sumif and Averages? 04-15-2011, 05:52 AM
byepeeps Re: Sumif and Averages? 04-27-2011, 12:05 PM
daddylonglegs Re: Sumif and Averages? 04-28-2011, 05:30 AM
byepeeps Re: Sumif and Averages? 05-02-2011, 06:37 PM
martindwilson Re: Sumif and Averages? 05-02-2011, 07:08 PM
daddylonglegs Re: Sumif and Averages? 05-04-2011, 09:01 AM
  1. #1
    Registered User
    Join Date
    01-09-2007
    Posts
    43

    Question Sumif and Averages?

    HI,

    I currently have been using the following formula for getting aggregate total of specific columns:

    =SUMIF(Sheet2!$B$3:$B$435,$A2,Sheet2!$I$3:$I$435)

    Now I want to use it in almost the same way but instead of an aggregate total, I'd like an average. So I would like this part of the formula !$I$3:$I$435 to produce an average. How do I do that?

    Best,
    Alex

  2. #2
    Forum Guru TMS's Avatar
    Join Date
    07-15-2010
    Location
    The Great City of Manchester, NW England ;-)
    MS-Off Ver
    MSO 2007,2010,365
    Posts
    48,465

    Re: Sumif and Averages?

    Try:

    =SUMIF(Sheet2!$B$3:$B$435,$A2,Sheet2!$I$3:$I$435)/COUNTIF(Sheet2!$B$3:$B$435,$A2)


    Regards
    Trevor Shuttleworth - Retired Excel/VBA Consultant

    I dream of a better world where chickens can cross the road without having their motives questioned

    'Being unapologetic means never having to say you're sorry' John Cooper Clarke


  3. #3
    Registered User
    Join Date
    01-09-2007
    Posts
    43

    Re: Sumif and Averages?

    Thanks for your reply and suggestion. It works, there's just one problem. The average isn't being calculated by the number of values, it's currently using the number of cells in the range (of which I have more than the number of sum_range cells).

    It might be better to show you:

    Range
    heading 1
    heading 1
    heading 1
    heading 1
    heading 1

    Sum_range
    3
    5
    2

    Above is an example of just one range selection and one sum selection. Currently the formula is working out an average by adding up the sum_range and diving by the number of range cells.

    So in the above example the calculation would be 10/5. What I'd like to achieve is to get the average based on how many cell are in the sum_range. So in this example it would be 10/3.

    Is that possible?

  4. #4
    Forum Guru TMS's Avatar
    Join Date
    07-15-2010
    Location
    The Great City of Manchester, NW England ;-)
    MS-Off Ver
    MSO 2007,2010,365
    Posts
    48,465

    Re: Sumif and Averages?

    I'm sorry, I don't really understand your example.

    A sample workbook with some typical data would me, and others, to picture the problem and put it into context. You're more likely to get a realistic response that way.

    Regards

  5. #5
    Forum Expert daddylonglegs's Avatar
    Join Date
    01-14-2006
    Location
    England
    MS-Off Ver
    Microsoft 365
    Posts
    14,721

    Re: Sumif and Averages?

    Try an "array formula" like this

    =AVERAGE(IF(Sheet2!$B$3:$B$435=$A2,IF(ISNUMBER(Sheet2!$I$3:$I$435),Sheet2!$I$3:$I$435)))

    confirmed with CTRL+SHIFT+ENTER
    Audere est facere

  6. #6
    Registered User
    Join Date
    01-09-2007
    Posts
    43

    Re: Sumif and Averages?

    Thanks for trying to answer this. I tried 'daddylonglegs' formula but couldn't get it to work.

    The formula by TMShucks is closest:
    =SUMIF(Sheet2!$B$3:$B$435,$A2,Sheet2!$I$3:$I$435)/COUNTIF(Sheet2!$B$3:$B$435,$A2)

    But there's just one problem. The average isn't being calculated by the number of values, it's currently using the number of cells in the range (of which I have more than the number of sum_range cells).

    Please see attached dummy spreadsheet. In sheet1 is the data I want to work from. Sheet2 has the output using the above formula. I've also included a column (C) which has the correct averages in. You'll notice the averages using the above formula are slightly out because it's dividing by the amount of 'Group' cells rather than the amount of 'Group' cells with values in.

    How do I fix this without removing the gaps (the main spreadsheet that I'm using this with needs to keep those gaps in the query column)?

    Thanks,
    Alex
    Attached Files Attached Files

  7. #7
    Forum Expert daddylonglegs's Avatar
    Join Date
    01-14-2006
    Location
    England
    MS-Off Ver
    Microsoft 365
    Posts
    14,721

    Re: Sumif and Averages?

    The array version I suggested works but you need to confirm with CTRL+SHIFT+ENTER so that curly braces appear around the formula

    ......but as you are using Excel 2007 (or 2010?) you can use AVERAGEIF function which will ignore the blanks anyway and doesn't need "array entering", i.e. for your example

    =AVERAGEIF(Sheet1!A$2:A$100,$A2,Sheet1!C$2:C$100)

  8. #8
    Registered User
    Join Date
    01-09-2007
    Posts
    43

    Question Re: Sumif and Averages?

    Can anyone help with this? I'm still stuck. Please read the above post and see the dummy spreadsheet I attached to it.

    Thanks,
    Alex

  9. #9
    Forum Expert martindwilson's Avatar
    Join Date
    06-23-2007
    Location
    London,England
    MS-Off Ver
    office 97 ,2007
    Posts
    19,320

    Re: Sumif and Averages?

    or another way
    =SUMIF(Sheet1!$A$2:$A$23,$A2,Sheet1!$C$2:$C$23)/SUMPRODUCT((Sheet1!$A$2:$A$23=$A2)*(Sheet1!$C$2:$C$23<>""))
    but the array formula
    =AVERAGE(IF(Sheet1!A2:A25=$A2,IF(ISNUMBER(Sheet1!C2:C25),Sheet1!C2:C25)))
    should give the same result
    Last edited by martindwilson; 05-02-2011 at 07:17 PM.
    "Unless otherwise stated all my comments are directed at OP"

    Mojito connoisseur and now happily retired
    where does code go ?
    look here
    how to insert code

    how to enter array formula

    why use -- in sumproduct
    recommended reading
    wiki Mojito

    how to say no convincingly

    most important thing you need
    Martin Wilson: SPV
    and RSMBC

  10. #10
    Forum Expert daddylonglegs's Avatar
    Join Date
    01-14-2006
    Location
    England
    MS-Off Ver
    Microsoft 365
    Posts
    14,721

    Re: Sumif and Averages?

    Did you try AVERAGEIF function using the formula I suggested? I put this formula in D2 and copied it to D3

    =AVERAGEIF(Sheet1!A$2:A$100,$A2,Sheet1!C$2:C$100)

    see attached
    Attached Files Attached Files

+ 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