+ Reply to Thread
Results 1 to 9 of 9

Trying to take an average of numbers in specific cells...

  1. #1
    Registered User
    Join Date
    11-04-2008
    Location
    London
    Posts
    20

    Trying to take an average of numbers in specific cells...

    What im trying to do is to take an average of a set of numbers that are next to a certain number in the next column.... this is going to be hard to explain

    Basically.... in one column i will have either a 0, 1, 2 or 3. and this could be listed down like this (these are priorities):

    Please Login or Register  to view this content.
    and what i need to do is to take an average of the value of the cell next to a specific number.... for example:

    Please Login or Register  to view this content.
    So i would have a formula for each of the priorities in a cell that would average the numbers to the right of that priority...

    So for example... the average of all priority 2's should be 10+12+30/3 = 17.333. ok now for the twist.....

    I may have a 0 value in a cell next to a priority... i do not want this to be averaged. This is my main problem. I have been using a combination of SUMIF functions and COUNTIF functions but cant get anything to work. Here is where i have got so far (e.g. for a priority 2):

    Please Login or Register  to view this content.
    - This seems fine.... this is summing the amounts next to a priority... its the next bit thats tricky... i now need to divide this by the number of cells with a value in it (>0) next to that priority (2)

    I can do the
    Please Login or Register  to view this content.
    but i only need the values next to 2. Can anyone help?

  2. #2
    Forum Expert
    Join Date
    08-27-2008
    Location
    England
    MS-Off Ver
    2010
    Posts
    2,561
    =sumif(a1:a10,"=2",b1:b10)/sumproduct((a1:a10=2)*(b1:b10<>0))


    hth
    Last edited by Cheeky Charlie; 11-13-2008 at 11:56 AM. Reason: Stop being a thickie CC

  3. #3
    Forum Expert Ron Coderre's Avatar
    Join Date
    03-22-2005
    Location
    Boston, Massachusetts
    MS-Off Ver
    2013, 2016, O365
    Posts
    6,996

    Calculating conditional averages

    With A1:B11 containing this list:
    Please Login or Register  to view this content.
    and...
    D1: Priority
    D2: 0
    D3: 1
    D4: 2
    D5: 3

    E1: Average

    Then...this formula returns the average for Priority 0 items
    Please Login or Register  to view this content.
    Copy that formula down through E5

    ..OR...you could use a Pivot Table to automatically build the table.
    Still using the above example...(Column heading must exist):
    From the Excel Main Menu: <Data><Pivot Table>
    Use: Excel……Click [Next]
    Select your data…(A1:B11)…Click [Next]
    Click the [Layout] button

    ROW: Drag the Priority field here
    COLUMN: (leave this area blank)
    DATA: Drag the Value field here
    If it doesn't list as Average of Value...dbl-click it and set it to Average
    Click [OK]
    Select where you want the Pivot Table…Click [Finish].

    That will list each Priority and the Average Value.

    Does that help?
    To refresh the Pivot Table, just right click it and select Refresh Data
    Ron
    Former Microsoft MVP - Excel (2006 - 2015)
    Click here to see the Forum Rules

  4. #4
    Forum Expert
    Join Date
    08-27-2008
    Location
    England
    MS-Off Ver
    2010
    Posts
    2,561
    I may have a 0 value in a cell next to a priority... i do not want this to be averaged
    Ron, I missed this first time through - am I right in thinking you did too?

  5. #5
    Registered User
    Join Date
    11-04-2008
    Location
    London
    Posts
    20
    yeh... thats my problem guys... is it possible?

  6. #6
    Forum Expert Ron Coderre's Avatar
    Join Date
    03-22-2005
    Location
    Boston, Massachusetts
    MS-Off Ver
    2013, 2016, O365
    Posts
    6,996

    Calculating conditional averages

    Yes....I surely missed the "skip zeros" critria, too.

    Ok....Using the same example I posted
    Try this formula
    Please Login or Register  to view this content.
    or...this shorter ARRAY FORMULA...BUT you need to remember to commit
    it with CTRL+SHIFT+ENTER (instead of just ENTER)
    Please Login or Register  to view this content.
    Copy the formula down through E5.

    Does that help?

  7. #7
    Registered User
    Join Date
    11-04-2008
    Location
    London
    Posts
    20
    ok the first formula works well thats great. What do you mean by commit? what does ctrl+shift+del do?

  8. #8
    Forum Expert Ron Coderre's Avatar
    Join Date
    03-22-2005
    Location
    Boston, Massachusetts
    MS-Off Ver
    2013, 2016, O365
    Posts
    6,996

    ARRAY FORMULAS and C+S+E

    It's CTRL+SHIFT+ENTER

    Regarding:
    Please Login or Register  to view this content.
    To make Excel treat the referenced cells as proper arrays,
    after editing the cell you must:
    • Hold down CTRL and SHIFT when you press ENTER

    If you just commit the formula with ENTER..it will return incorrect values.
    That's one of the pitfalls of ARRAY FORMULAS.

    I hope that helps.

  9. #9
    Forum Expert
    Join Date
    08-27-2008
    Location
    England
    MS-Off Ver
    2010
    Posts
    2,561
    I think the sumproducts version I wrote first is neater...

+ Reply to Thread

Thread Information

Users Browsing this Thread

There are currently 1 users browsing this thread. (0 members and 1 guests)

Tags for this Thread

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