How to use one column of text as an identifier to average a second column number

My title doesn't describe what I'm doing so I'll just explain. I've built a spreadsheet to track my workouts (yes, I'm a dork) and I'm trying to compare trainers to see who has the highest average calorie burn. I've set it like below. Each row will have a workout.



Workout date Trainer

Calorie Burn

1/1/15

Fred 750

1/2/15

Mary 725

1/3/15

Fred 800

1/4/15

Sam 850

1/5/15

Sam 800



I'd like to build a chart that can average the calorie column and organize into a chart by Trainer name.


Trainer Average Calorie Burn
Fred

775

Mary 725
Sam 825


Is there a formula or a way to do this with a chart in Numbers? I appreciate any assistance.

iMac (27-inch, Late 2013), OS X Mountain Lion (10.8.5), 24 GB Ram, 512 GB SSD

Posted on Jan 9, 2015 1:14 PM

Reply
9 replies

Jan 9, 2015 1:41 PM in response to Ennoxx

the average() function will do the trick:


User uploaded file


The data table in the example is titled "Table 1"


for the summary table (the lower table), enter the names in column A.


B2=AVERAGEIF(Table 1::B, A2, Table 1::C)


this is shorthand for .... select cell B2, then type (or copy and paste from here) the formula:

=AVERAGEIF(Table 1::B, A2, Table 1::C)


select cell B2, copy

select cells B2 thru the end of the column, paste


if you want the averages to be empty when there is no name type in column A use this formula instead:

B2=IF(LEN(A2)=0, "", AVERAGEIF(Table 1::B, A2, Table 1::C))

Jan 10, 2015 8:08 PM in response to Jerrold Green1

Thank you very much! This is exactly what I wanted.


Average Calories by Trainer

Natalie

720

Michael

954

Jason

718

Elvis

688


One last question since you were all so helpful. How do I sort by the Average calorie burn column from highest to lowest? Every time I try to sort, it messes up all the formulas or won't change the names, just the numbers. In excel it's so easy to do this, I'm so surprised that I'm having issues sorting too! Ideally I'd like it to automatically sort to have the highest trainer on top, but I'm ok doing it manually if I need to.


Thanks again!

Jan 10, 2015 8:23 PM in response to Ennoxx

Sorting in Numbers V3 is a mess. An easy way to avoid the problem is to use LOOKUP. Here's an example for your case:

User uploaded file

The expression in RANK of Summary aux table is:


=RANK(B, B)


The expression in Trainer column of Summary by Trainer is:


=LOOKUP(ROW()−1, Summary aux table::C, Summary aux table::A)


The expression in Average Calorie Burn in Summary by Trainer is:


=LOOKUP(ROW()−1, Summary aux table::C, Summary aux table::B)


By doing this, the row of the table determines which rank is displayed. The Aux table may be hidden by putting it on another Sheet or by putting a White Shape over it.


Jerry

Jan 10, 2015 8:32 PM in response to Ennoxx

There is an enhancement that prevents problems with tie scores which you may want to consider. Just a small amount of additional code:

User uploaded file

By adding a very small offset depending on the row in the table, there will never by a tie.


The expression in Summary aux table, Column B is now:


=AVERAGEIF(Log::B, A2, Log::C)+ROW()÷10000


and, the expression now in Summary by Trainer, Column B is now:


=ROUND(LOOKUP(ROW()−1, Summary aux table::C, Summary aux table::B), 0)


Regards,


Jerry

This thread has been closed by the system or the community team. You may vote for any posts you find helpful, or search the Community for additional answers.

How to use one column of text as an identifier to average a second column number

Welcome to Apple Support Community
A forum where Apple customers help each other with their products. Get started with your Apple Account.