Apple Event: May 7th at 7 am PT

Looks like no one’s replied in a while. To start the conversation again, simply ask a new question.

Mac Numbers 3.6.1: Averageif Function

Hi,


I need some help with using the Averageif function in Numbers 3.6.1.


In this example, I am trying to find the sum of the masses of the students who are shorter than 160 cm (to which it should return 150, since only students 1, 3 and 4 fit the criterion, and the sum of their masses is 40 + 50 + 60 = 150). As seen in cell E4, I have put in the formula =SUMIF(Height (cm), <160, Mass (kg)) but when I press return, it tells me that "The formula contains a syntax error". What have I done wrong?


In cell E3, I put in =SUMIF(Height (cm), 170, Mass (kg)) to which it correctly returned 120 (only students 2 and 5 have height 170 cm, and the sum of their masses is 50 + 70 = 120). So is it just that I am not allowed to use the < argument? If so, is there any way around it?


User uploaded file


Thanks

Posted on Apr 30, 2016 9:52 AM

Reply
Question marked as Best reply

Posted on Apr 30, 2016 12:07 PM

In your formula where you have


<160


try replacing that with


"<"&160


SG

3 replies

Apr 30, 2016 6:22 PM in response to Wai Hung Tony

Hi Wai Hung Tony,


The bugaboo here is that condition statements must be presented as a text string. The function descriptions in the browser and in Numbers Help (and in the Formulas and functions User Guide which applied to the earlier Numbers '09) never come right out and say that, but the examples given with each of the XXXIF and XXXIFS functions show it in every case where a comparison operator is used.

The second example in your initial post, "=SUMIF(Height (cm), 170, Mass (kg))", shows the only exception: if the operator is omitted, the default comparison is "equal to," and the function will recognize a number as a valid comparison value.

Replacing <160 with "<"&160 (as suggested in SG's post above), or with "<160" as shown in Apple's examples makes the comparison statement a text string, and avoids the error.



You mention "AVERAGEIF" in your question, which leads me to assume you are using SUMIF as a step toward calculating the average of the summed masses.


Since AVERAGEIF will give you that result without the need to also use COUNTIF, you might want to use it, as I've done in the example below.

User uploaded file

Formula shown for E4: AVERAGEIF(B,">=160",C)

Formula in E3: AVERAGEIF(B,"<160",C)


Note the inclusion of "=" in one of the formulas. If this were not done, neither 'average' figure would include any students whose height was recorded as 160 cm.


Regards,

Barry

May 1, 2016 6:48 AM in response to Wai Hung Tony

The condition statement can be entered as "just a number." For example, if you wanted to count how many times 50 occurs in column B you could just do:


=COUNTIF(B,50)


But when you have a comparison operator such as < or <=, etc. you need to wrap it in " " and concatenate the condition with &, as in the example in my post above.


SG

Mac Numbers 3.6.1: Averageif Function

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