+ Reply to Thread
Results 1 to 9 of 9

Averaging cells in one column, based on another

  1. #1
    Registered User
    Join Date
    03-21-2021
    Location
    London England
    MS-Off Ver
    Office 2021
    Posts
    6

    Question Averaging cells in one column, based on another

    Hello everyone,

    I have multiple CSV files, which look something like this
    34 8800
    30 10500
    30 10900
    30 8000
    31 7600
    31 8000
    34 8400
    33 8500
    34 8800
    32 8300
    35 9100
    35 9000
    39 9900
    37 9200
    34 8400
    36 8900
    36 9300


    Where the first column is size of an ArrayList, and the second one is time needed to perform an operation on the ArrayList.
    What I need to do is to have all the values from first column that are same merge, and create an average of the values from second column that match them.
    Something that would look like this


    30 9800
    31 7800
    32 8300
    33 8500
    34 8600
    35 9050
    36 9100
    37 9200
    39 9900


    What I've been able to come up with so far is using something like this =AVERAGEIFS(B:B;A:A;">X";A:A;"<=Y") where it would average the cells in the interval (X,Y> , but if I want to do what I described using this method I would have to manually type in the interval for each individual value of first column which is something I'd like to avoid if possible.
    Is there a function that would do all that for me automatically?


    Thanks in advance!

  2. #2
    Forum Expert
    Join Date
    05-05-2015
    Location
    UK
    MS-Off Ver
    Microsoft Excel for Microsoft 365 MSO (Version 2402 Build 16.0.17328.20068) 64-bit
    Posts
    28,191

    Re: Averaging cells in one column, based on another

    Fast answers need visual help. Please read the yellow banner at the top of this page on how to attach a file.

  3. #3
    Forum Expert etaf's Avatar
    Join Date
    10-22-2004
    Location
    Wittering, West Sussex, UK
    MS-Off Ver
    365 (Mac OSX) (16.83 (24031120))
    Posts
    8,737

    Re: Averaging cells in one column, based on another

    can you use a pivot table
    OR
    does this have to stay in CSV Format?

    See attached
    Attached Files Attached Files
    Wayne
    if my assistance has helped, and only if you wish to , there is an "* Add Reputation" on the left hand side - you can add to my reputation here

    If you have a solution to your thread - Please mark your thread solved do the following: >
    Select Thread Tools-> Mark thread as Solved. To undo, select Thread Tools-> Mark thread as Unsolved.

  4. #4
    Forum Expert
    Join Date
    09-07-2014
    Location
    Israel
    MS-Off Ver
    office 365 for MAC
    Posts
    3,105

    Re: Averaging cells in one column, based on another

    Hi
    How about that?
    D2 and down:
    =IFERROR(INDEX($A$1:$A$17,AGGREGATE(15,6,ROW($A$1:$A$17)/(COUNTIF($D$1:D1,$A$1:$A$17)=0),1)),"")

    E2 and down:
    =+AVERAGEIF(A1:A17,D2,B1:B17)
    Attached Files Attached Files

  5. #5
    Registered User
    Join Date
    03-21-2021
    Location
    London England
    MS-Off Ver
    Office 2021
    Posts
    6

    Re: Averaging cells in one column, based on another

    Quote Originally Posted by etaf View Post
    can you use a pivot table
    OR
    does this have to stay in CSV Format?

    See attached
    Thanks for the answer. Yes I can use pivot table I just didnt realize such thing even existed even after searching for quite some time. I am going to try and set it up, thank you very much!

  6. #6
    Forum Expert
    Join Date
    09-07-2014
    Location
    Israel
    MS-Off Ver
    office 365 for MAC
    Posts
    3,105

    Re: Averaging cells in one column, based on another

    If you want column D to be sorted in ascending way use this
    D2 and down -
    =IFERROR(AGGREGATE(15,6,($A$1:$A$17)/(ROW($A$1:$A$17)=MATCH($A$1:$A$17,$A$1:$A$17,0)),ROWS($A$1:A1)),"")

  7. #7
    Registered User
    Join Date
    03-21-2021
    Location
    London England
    MS-Off Ver
    Office 2021
    Posts
    6

    Re: Averaging cells in one column, based on another

    Quote Originally Posted by belinda200 View Post
    Hi
    How about that?
    D2 and down:
    =IFERROR(INDEX($A$1:$A$17,AGGREGATE(15,6,ROW($A$1:$A$17)/(COUNTIF($D$1:D1,$A$1:$A$17)=0),1)),"")

    E2 and down:
    =+AVERAGEIF(A1:A17,D2,B1:B17)
    Thank you very much this is exactly what I was looking for!
    Just one last question.
    In the second function I can replace the range with A:A and B:B, but when I do the same thing with the first function it takes quite some time to calculate all the rows.
    However if I type in the range manually it happens instantly, even if the last cell is on row 25000+. Is it possible to define the range from A1 cell to the last non blank cell in the row?

  8. #8
    Forum Expert
    Join Date
    09-07-2014
    Location
    Israel
    MS-Off Ver
    office 365 for MAC
    Posts
    3,105

    Re: Averaging cells in one column, based on another

    My Advice: Dont take the whole column into calculation. Define a range that will take a significant spare cells.

  9. #9
    Registered User
    Join Date
    03-21-2021
    Location
    London England
    MS-Off Ver
    Office 2021
    Posts
    6

    Re: Averaging cells in one column, based on another

    Alright, I will follow your advice then! I will now mark the thread as solved. Thanks belinda and everyone else!

+ 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. Replies: 5
    Last Post: 03-31-2015, 03:24 PM
  2. Help With Conditional Averaging Based On Column Header...
    By jeffgreg in forum Excel Formulas & Functions
    Replies: 1
    Last Post: 01-15-2014, 08:56 PM
  3. Dynamic averaging based on adjacent column.
    By projectatpel in forum Excel Formulas & Functions
    Replies: 3
    Last Post: 12-20-2013, 02:21 PM
  4. [SOLVED] Averaging a column based on boundaries set at a different column
    By Kybynn in forum Excel Formulas & Functions
    Replies: 9
    Last Post: 01-11-2013, 10:39 AM
  5. Averaging based on different Column
    By corky1111 in forum Excel General
    Replies: 5
    Last Post: 08-12-2011, 02:12 PM
  6. When Averaging a column, exclude value based on another cell value
    By Divercem in forum Excel Formulas & Functions
    Replies: 6
    Last Post: 08-21-2006, 06:40 PM
  7. [SOLVED] Averaging Cells Based On Conditions in Neighboring Cells
    By foofoo in forum Excel General
    Replies: 4
    Last Post: 06-20-2006, 10:20 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