+ Reply to Thread
Results 1 to 16 of 16

Find Average, Return Column Header of Number Closest To Average

  1. #1
    Registered User
    Join Date
    12-30-2010
    Location
    Portland, Oregon USA
    MS-Off Ver
    2007, 2010, 2016
    Posts
    35

    Find Average, Return Column Header of Number Closest To Average

    With a table like the one shown below, how can I find the average of each row, then determine which column header comes closest to the average?

    In other words, assuming rows A:E contain the values shown below, what formula would I use in row F to get the column header above the number that comes closest to the average for that row?

    1BR 2BR 3BR 4BR
    Fruitridge 1 2 3 4
    Grapeview 5 6 7 8
    Orangevale 1 2 3 4
    Appleton 5 6 7 8
    Fruitridge 1 2 3 4
    Grapeview 5 6 7 8
    Orangevale 1 2 3 4
    Appleton 5 6 7 8

    Thanks!

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

    Re: Find Average, Return Column Header of Number Closest To Average

    in all those examples the average is midway between any given number so is it nearest high or low? required also will numbers always be ascending left to right
    please give a more realistic example
    Last edited by martindwilson; 07-06-2013 at 09: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

  3. #3
    Registered User
    Join Date
    12-30-2010
    Location
    Portland, Oregon USA
    MS-Off Ver
    2007, 2010, 2016
    Posts
    35

    Re: Find Average, Return Column Header of Number Closest To Average

    Thanks for asking that, martindwilson!

    I actually was going to mention that in my original post, but thought it might be complicating the question.

    My preference is to "round up" so that the result, if stuck between columns, defaults to the column on the right.

  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: Find Average, Return Column Header of Number Closest To Average

    The average for the 1st row of data is 2.5.

    Fruitridge 1 2 3 4

    So, which number is closest to 2.5? Is it 2 or 3?
    Biff
    Microsoft MVP Excel
    Keep It Simple Stupid

    Let's Go Pens. We Want The Cup.

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

    Re: Find Average, Return Column Header of Number Closest To Average

    Quote Originally Posted by djmyers View Post
    My preference is to "round up" so that the result, if stuck between columns, defaults to the column on the right.
    OK, try this...

    =INDEX(B$1:E$1,MATCH(CEILING(AVERAGE(B2:E2),1),B2:E2,0))

  6. #6
    Registered User
    Join Date
    12-30-2010
    Location
    Portland, Oregon USA
    MS-Off Ver
    2007, 2010, 2016
    Posts
    35

    Re: Find Average, Return Column Header of Number Closest To Average

    Hi Tony,

    I probably should have posted a more "real world" example where the averages don't fall "between columns" (so to speak) very frequently.

    As I mentioned just above, I'd like to default to the column to the right when the average is at a mid-point between two columns, unless there's some kind of magical way to return a value that indicates the average fell exactly between two columns, and indicates which those two columns are.

    Thanks!

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

    Re: Find Average, Return Column Header of Number Closest To Average

    How about posting some more realistic examples and tell us what results you expect.

  8. #8
    Registered User
    Join Date
    12-30-2010
    Location
    Portland, Oregon USA
    MS-Off Ver
    2007, 2010, 2016
    Posts
    35

    Re: Find Average, Return Column Header of Number Closest To Average

    Tony,

    Your formula seemed to work for the example I posted, but I can seem to make it work on this more realistic table:

    B Col Header C Col Header D Col Header E Col Header
    Row 2 5.05 5.23 5.35 5.54
    Row 3 6.78 7.33 8.42 8.81
    Row 4 7.69 8.13 9.06 9.55
    Row 5 5.32 5.44 5.84 7.48
    Row 6 6.95 7.55 8.55 9.01
    Row 7 7.94 8.16 9.20 9.82
    Row 8 5.05 5.23 5.35 5.54
    Row 9 5.49 6.39 7.36 7.95
    Row 10 7.27 7.75 8.70 9.22
    Row 11 5.32 5.44 5.84 7.48
    Row 12 6.16 7.25 8.10 8.47
    Row 13 7.54 7.94 8.93 9.39

  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: Find Average, Return Column Header of Number Closest To Average

    It would have been better for us if you would have told us what results you expect.

    Here's my best guess...

    This array formula** entered in F2 and copied down:

    =INDEX(B$1:E$1,MATCH(TRUE,B2:E2>=AVERAGE(B2:E2),0))

    ** array formulas need to be entered using the key
    combination of CTRL,SHIFT,ENTER (not just ENTER).
    Hold down both the CTRL key and the SHIFT key
    then hit ENTER.

    I'm assuming that if by chance the number IS equal to the average then that's the match you want.

  10. #10
    Registered User
    Join Date
    12-30-2010
    Location
    Portland, Oregon USA
    MS-Off Ver
    2007, 2010, 2016
    Posts
    35

    Re: Find Average, Return Column Header of Number Closest To Average

    Thanks, Tony. That formula certainly seems to do as I asked.

    I've tried to modify it so that it will display the column header of the number closest to average. If that number is lower, the column header on the left would show. Can't seem to make that work.

    Any suggestions?

  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: Find Average, Return Column Header of Number Closest To Average

    Post a SMALL sample file (about 20 rows worth of data will do) with realistic data and show us the results you expect for each row of data.

    I'm getting ready to logout for the day so I won't be able to get back to this until tomorrow.

  12. #12
    Registered User
    Join Date
    12-30-2010
    Location
    Portland, Oregon USA
    MS-Off Ver
    2007, 2010, 2016
    Posts
    35

    Re: Find Average, Return Column Header of Number Closest To Average

    Thanks Biff / Tony.

    (Don't know whether to address you by your signature or user name.)

    I'll be able to post a small realistic example on Monday. (Unfortunately, I left that worksheet at work.)

    Kind regards,

    Dave Myers

  13. #13
    Registered User
    Join Date
    12-30-2010
    Location
    Portland, Oregon USA
    MS-Off Ver
    2007, 2010, 2016
    Posts
    35

    Re: Find Average, Return Column Header of Number Closest To Average

    In the meantime, attached is a worksheet that shows the example table in columns A:E.

    Column F shows the average for each row.

    Column G shows the value found in A:E that comes closest to the average value for that row.

    Column H displays the column header that corresponds to the column where the value closest to average was found.

    What I'm trying to do is roll all this into one formula so that it becomes a one-step process.
    Attached Files Attached Files

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

    Re: Find Average, Return Column Header of Number Closest To Average

    You had all the individual steps worked out! Here's the single formula:

    Array entered**:

    =INDEX(B$1:E$1,MATCH(MIN(ABS(B2:E2-AVERAGE(B2:E2))),ABS(B2:E2-AVERAGE(B2:E2)),0))

    ** array formulas need to be entered using the key
    combination of CTRL,SHIFT,ENTER (not just ENTER).
    Hold down both the CTRL key and the SHIFT key
    then hit ENTER.

    Copy down

  15. #15
    Registered User
    Join Date
    12-30-2010
    Location
    Portland, Oregon USA
    MS-Off Ver
    2007, 2010, 2016
    Posts
    35

    Re: Find Average, Return Column Header of Number Closest To Average

    Tony / Biff,

    Works like a champ!!

    Thanks so much!

    Kind regards,

    Dave Myers

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

    Re: Find Average, Return Column Header of Number Closest To Average

    You're welcome. Thanks for the feedback!

+ 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