+ Reply to Thread
Results 1 to 16 of 16

Help with a formula to average if cell value appears in one of two columns

  1. #1
    Registered User
    Join Date
    11-07-2012
    Location
    London
    MS-Off Ver
    Excel 2010
    Posts
    76

    Help with a formula to average if cell value appears in one of two columns

    Please help me with this formula

    I need a formula to find the average of the numbers in column C: of Oeste's (cell B1) games within the table below.
    If Oeste appears in column A, take number in C
    If Oeste appears in column B, take the number in C multipled by -1

    pls see attachment

    Thanks

  2. #2
    Forum Expert BadlySpelledBuoy's Avatar
    Join Date
    06-14-2013
    Location
    East Sussex, UK
    MS-Off Ver
    365
    Posts
    7,468

    Re: Help with a formula to average if cell value appears in one of two columns

    One quick and easy way would be to use a helper column.

    Put the below formula in E11 and copy down to E42.
    =IF(A11=B$1,C11,IF(B11=B$1,C11*-1,""))

    Then use =AVERAGE(E11:E42) to get the result you're looking for.

    BSB

  3. #3
    Registered User
    Join Date
    11-07-2012
    Location
    London
    MS-Off Ver
    Excel 2010
    Posts
    76

    Re: Help with a formula to average if cell value appears in one of two columns

    Thanks BSB.

    Yes that would help, however ultimately I planned to create a table with all the teams showing these averages within a range.
    pls see the new attachement, so here I have all teams listed B1:B20 where i'd like the averages next to them .
    I don't think the helper column can help to allow this

    Thanks

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

    Re: Help with a formula to average if cell value appears in one of two columns

    Or, all in one:

    =SUMPRODUCT(--(($A$11:$A$42=$B$1)+($B$11:$B$42=$B$1))*$C$11:$C$42*{1,1})/COUNTIF($A$11:$B$42,$B$1)
    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.

    Temporary addition of accented to illustrate ongoing problem to the TT: L? fh?ile P?draig sona dhaoibh

  5. #5
    Registered User
    Join Date
    11-07-2012
    Location
    London
    MS-Off Ver
    Excel 2010
    Posts
    76

    Re: Help with a formula to average if cell value appears in one of two columns

    Ah that's it, brilliant..
    Thanks Glenn

  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 2403
    Posts
    44,053

    Re: Help with a formula to average if cell value appears in one of two columns

    Hold fire. It's incorrect. It's coincidentally similar. Look back in five mins.
    Last edited by Glenn Kennedy; 01-14-2021 at 04:37 AM.

  7. #7
    Registered User
    Join Date
    11-07-2012
    Location
    London
    MS-Off Ver
    Excel 2010
    Posts
    76

    Re: Help with a formula to average if cell value appears in one of two columns

    Ok thanks. I was actually noticing some issues, and still am even with the newest formula hmm.
    The average of Oeste should be coming up exactly -0.26
    (0.06 + 0.76 - 1.02 - 0.84)/4
    but the formula is actually returning -0.2615. When I put a different team in B1, the numbers don't seem to be correct.
    Have to pop out now but will test again in a while to give more examples

  8. #8
    Forum Expert bebo021999's Avatar
    Join Date
    07-22-2011
    Location
    Vietnam
    MS-Off Ver
    Excel 2016
    Posts
    9,466

    Re: Help with a formula to average if cell value appears in one of two columns

    #4's shorter version

    Please Login or Register  to view this content.
    Quang PT

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

    Re: Help with a formula to average if cell value appears in one of two columns

    This array formula works:
    =SUM(IF($A$11:$A$42=$B$1,$C$11:$C$42,IF($B$11:$B$42=B1,-$C$11:$C$42,"")))/COUNTIF($A$11:$B$42,$B$1)

    These are a little different from ordinary formulae in that they MUST be confirmed in the FIRST CELL ONLY by pressing CTRL+SHIFT+ENTER to activate the array, not just ENTER. After that, the array can be dragged down as normal, to cover the desired range.

    You will know the array is active when you see the curly brackets { } appear around the outside of your formula. If you do not use CTRL+SHIFT+ENTER you will (almost always) get an error message or an incorrect answer. Press F2 on that cell and try again.

    Don't type the curly brackets yourself - it won't work...

  10. #10
    Forum Expert bebo021999's Avatar
    Join Date
    07-22-2011
    Location
    Vietnam
    MS-Off Ver
    Excel 2016
    Posts
    9,466

    Re: Help with a formula to average if cell value appears in one of two columns

    Column C itself with 3-4 decimals, so you wish to round it?

    Try again:

    Please Login or Register  to view this content.

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

    Re: Help with a formula to average if cell value appears in one of two columns

    Bebo got it.... I haven't had my coffee yet!!

  12. #12
    Registered User
    Join Date
    11-07-2012
    Location
    London
    MS-Off Ver
    Excel 2010
    Posts
    76

    Re: Help with a formula to average if cell value appears in one of two columns

    Thanks guys. That definitely works well.

    One more question. How would the formula need to change to work if I introduced a gap (another column, empty or not) between columns A and B?
    the formula is now returning #N/A
    Attached Images Attached Images

  13. #13
    Registered User
    Join Date
    11-07-2012
    Location
    London
    MS-Off Ver
    Excel 2010
    Posts
    76

    Re: Help with a formula to average if cell value appears in one of two columns

    Seems like it would just be a case of changing the {1,-1} to {1,0,-1}.

    Thanks all.

  14. #14
    Forum Guru
    Join Date
    08-28-2014
    Location
    USA
    MS-Off Ver
    Excel 2019
    Posts
    17,560

    Re: Help with a formula to average if cell value appears in one of two columns

    Based on the screen shot in post #12, try modifying bebo's formula to read:
    Formula: copy to clipboard
    Please Login or Register  to view this content.

    Let us know if you have any questions.
    Consider taking the time to add to the reputation of everybody that has taken the time to respond to your query.

  15. #15
    Registered User
    Join Date
    11-07-2012
    Location
    London
    MS-Off Ver
    Excel 2010
    Posts
    76

    Re: Help with a formula to average if cell value appears in one of two columns

    That's great, thanks

  16. #16
    Forum Guru
    Join Date
    08-28-2014
    Location
    USA
    MS-Off Ver
    Excel 2019
    Posts
    17,560

    Re: Help with a formula to average if cell value appears in one of two columns

    You're Welcome. Thank You for the feedback and for marking the thread as 'Solved'. I hope that you have a blessed day.

+ 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. Average between 2 dates if criteria appears in same row
    By aceme73 in forum Excel Formulas & Functions
    Replies: 3
    Last Post: 06-22-2015, 07:16 PM
  2. [SOLVED] need formula to average cells but if one cell has N/A then dont average and input N/A
    By CityInspector in forum Excel Formulas & Functions
    Replies: 3
    Last Post: 08-08-2013, 04:16 PM
  3. Replies: 5
    Last Post: 04-23-2013, 05:11 PM
  4. Replies: 5
    Last Post: 02-06-2012, 10:40 AM
  5. Replies: 1
    Last Post: 10-14-2011, 10:59 PM
  6. Copy certain rows and columns if data appears in one cell
    By pmarsella in forum Excel Programming / VBA / Macros
    Replies: 6
    Last Post: 08-21-2009, 04:11 AM
  7. text appears in formula bar but not in cell
    By lsparks in forum Excel General
    Replies: 8
    Last Post: 12-05-2008, 06:55 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