ExcelBanter

ExcelBanter (https://www.excelbanter.com/)
-   Excel Programming (https://www.excelbanter.com/excel-programming/)
-   -   applying function depending on condition in other cell (https://www.excelbanter.com/excel-programming/327871-applying-function-depending-condition-other-cell.html)

[email protected]

applying function depending on condition in other cell
 
Hi experts,

If I have data like this

A B
-------------
x 2
x 5
y 6
x 1
y 2
x 3

How do I include the values of column B in a function, only if the
values have a corresponding x in the A column. For example if I would
like to calculate the AVERAGE only of the values in B which has the
value X in A.

Jonas


Toppers

applying function depending on condition in other cell
 
Try:

Assumes data is in range a1 to b10

=Sumif(a1:a10,"x",b1:b10)/countif(a1:a10,"x")

HTH

" wrote:

Hi experts,

If I have data like this

A B
-------------
x 2
x 5
y 6
x 1
y 2
x 3

How do I include the values of column B in a function, only if the
values have a corresponding x in the A column. For example if I would
like to calculate the AVERAGE only of the values in B which has the
value X in A.

Jonas



[email protected]

applying function depending on condition in other cell
 
Great! Thanks a lot, I've always thought there was a smarter way to do
this than using only the "if"-statement and several new columns of
space, but I never new about "sumif" and "countif".
This is of course very appropriate for simple things as summing or
averaging, but is there also a more general way to do similar things
for an arbitrary function?

Jonas, very gratetful for the quick answer!


Bob Phillips[_6_]

applying function depending on condition in other cell
 
or

=AVERAGE(IF(A1:A10="x",B1:B10))

which is an array formula, so is committed with Ctrl-Shift-Enter

--

HTH

RP
(remove nothere from the email address if mailing direct)


"Toppers" wrote in message
...
Try:

Assumes data is in range a1 to b10

=Sumif(a1:a10,"x",b1:b10)/countif(a1:a10,"x")

HTH

" wrote:

Hi experts,

If I have data like this

A B
-------------
x 2
x 5
y 6
x 1
y 2
x 3

How do I include the values of column B in a function, only if the
values have a corresponding x in the A column. For example if I would
like to calculate the AVERAGE only of the values in B which has the
value X in A.

Jonas





Bob Phillips[_6_]

applying function depending on condition in other cell
 
My solution shows you that.

--

HTH

RP
(remove nothere from the email address if mailing direct)


wrote in message
ups.com...
Great! Thanks a lot, I've always thought there was a smarter way to do
this than using only the "if"-statement and several new columns of
space, but I never new about "sumif" and "countif".
This is of course very appropriate for simple things as summing or
averaging, but is there also a more general way to do similar things
for an arbitrary function?

Jonas, very gratetful for the quick answer!




[email protected]

applying function depending on condition in other cell
 
Thanks!
Today is a very nice day, never heard about array formulas before.
Seems extremely useful.

Jonas



All times are GMT +1. The time now is 12:17 AM.

Powered by vBulletin® Copyright ©2000 - 2025, Jelsoft Enterprises Ltd.
ExcelBanter.com