PC Review


Reply
Thread Tools Rate Thread

Array Formula Help -IF / Else clause?

 
 
Jay
Guest
Posts: n/a
 
      13th Aug 2006
Hi,

I'm just getting to grips with Array formulae, and one of the formula I
use most frequently is to count combinations of values over two arrays:
For example:

=SUM(IF(A1:A100="Ford",IF(B1:B100="Focus"1,0)))

To give a count of all the Ford Focus in a 2 column list/array (Make &
Model in columns A and B respectively)

I understand how it works. Creates (and sums) an array of 1s for every
combination where there is Ford & Focus.

But what I don't understand is how the second IF fits in.

Isn't the second IF basically the ELSE clause of the first IF? But
doesn't the formula almost work as if it's an AND? SUM the 1s IF A=Ford
*AND* B=Focus.

I don't understand how this fits my usual ubderstanding of the ELSE
clause of an IF statement. And I think it's this stumbling block that's
stopping me making greater use of such functions.

If anyone could enlighten me I'd really appreciate it?

TIA,

Jason

 
Reply With Quote
 
 
 
 
Peo Sjoblom
Guest
Posts: n/a
 
      13th Aug 2006
No, if both conditions are true return 1, if not it will be zero.
What you basically do is

=SUM((A1:A100="Ford")*(B1:B100="Focus"))

so it will be TRUE or FALSE and if there are 2 TRUE in the same row it will
retrun 1 when multiplied so it may look like

{0;0;0;0;0;0;1;0;0;0;0;0;0;0;0;0;0;0;0;0;0;0;0;0;0;0;0;0;0;0;0;0;0;0;0;0;0
etc.

and then SUM will sum all the 1s

you can write it as this and enter it normally

=SUMPRODUCT(--(A1:A100="Ford"),--(B1:B100="Focus"))

or if you use 2007 and the new function COUNTIFS

=COUNTIFS(A1:A100,"Ford",B1:B100,"Focus")

I only use sum array formulas when there is no other choice

--


Regards,

Peo Sjoblom

Excel 95 - Excel 2007
Northwest Excel Solutions
www.nwexcelsolutions.com
(remove ^^ from email)


"Jay" <(E-Mail Removed)> wrote in message
news:(E-Mail Removed)...
> Hi,
>
> I'm just getting to grips with Array formulae, and one of the formula I
> use most frequently is to count combinations of values over two arrays:
> For example:
>
> =SUM(IF(A1:A100="Ford",IF(B1:B100="Focus"1,0)))
>
> To give a count of all the Ford Focus in a 2 column list/array (Make &
> Model in columns A and B respectively)
>
> I understand how it works. Creates (and sums) an array of 1s for every
> combination where there is Ford & Focus.
>
> But what I don't understand is how the second IF fits in.
>
> Isn't the second IF basically the ELSE clause of the first IF? But
> doesn't the formula almost work as if it's an AND? SUM the 1s IF A=Ford
> *AND* B=Focus.
>
> I don't understand how this fits my usual ubderstanding of the ELSE clause
> of an IF statement. And I think it's this stumbling block that's stopping
> me making greater use of such functions.
>
> If anyone could enlighten me I'd really appreciate it?
>
> TIA,
>
> Jason
>



 
Reply With Quote
 
Dave Peterson
Guest
Posts: n/a
 
      13th Aug 2006
The second IF is not part of the "else", it's part of the "Then".

So if it's a ford, then if it's a focus, put 1. Very close to AND, huh?

Another way to do this same kind of thing:

=sumproduct(--(a1:a100="ford"),--(b1:b100="focus"))

Adjust the ranges to match--but you can't use whole columns.

=sumproduct() likes to work with numbers. The -- stuff changes trues and falses
to 1's and 0's.

Bob Phillips explains =sumproduct() in much more detail here:
http://www.xldynamic.com/source/xld.SUMPRODUCT.html

And J.E. McGimpsey has some notes at:
http://mcgimpsey.com/excel/formulae/doubleneg.html

Jay wrote:
>
> Hi,
>
> I'm just getting to grips with Array formulae, and one of the formula I
> use most frequently is to count combinations of values over two arrays:
> For example:
>
> =SUM(IF(A1:A100="Ford",IF(B1:B100="Focus"1,0)))
>
> To give a count of all the Ford Focus in a 2 column list/array (Make &
> Model in columns A and B respectively)
>
> I understand how it works. Creates (and sums) an array of 1s for every
> combination where there is Ford & Focus.
>
> But what I don't understand is how the second IF fits in.
>
> Isn't the second IF basically the ELSE clause of the first IF? But
> doesn't the formula almost work as if it's an AND? SUM the 1s IF A=Ford
> *AND* B=Focus.
>
> I don't understand how this fits my usual ubderstanding of the ELSE
> clause of an IF statement. And I think it's this stumbling block that's
> stopping me making greater use of such functions.
>
> If anyone could enlighten me I'd really appreciate it?
>
> TIA,
>
> Jason


--

Dave Peterson
 
Reply With Quote
 
Ragdyer
Guest
Posts: n/a
 
      13th Aug 2006
Besides the fact that you left a comma out of your posted formula, why not
get in the habit of using the non-array SumProduct() function, which is more
straight forward for comprehension:

=SUMPRODUCT((A1:A100="Ford")*(B1:B100="Focus"))

And if you have additional criteria to include, simply add another argument:

=SUMPRODUCT((A1:A100="Ford")*(B1:B100="Focus")*(C1:C100="Red"))

--
HTH,

RD

---------------------------------------------------------------------------
Please keep all correspondence within the NewsGroup, so all may benefit !
---------------------------------------------------------------------------
"Jay" <(E-Mail Removed)> wrote in message
news:(E-Mail Removed)...
> Hi,
>
> I'm just getting to grips with Array formulae, and one of the formula I
> use most frequently is to count combinations of values over two arrays:
> For example:
>
> =SUM(IF(A1:A100="Ford",IF(B1:B100="Focus"1,0)))
>
> To give a count of all the Ford Focus in a 2 column list/array (Make &
> Model in columns A and B respectively)
>
> I understand how it works. Creates (and sums) an array of 1s for every
> combination where there is Ford & Focus.
>
> But what I don't understand is how the second IF fits in.
>
> Isn't the second IF basically the ELSE clause of the first IF? But
> doesn't the formula almost work as if it's an AND? SUM the 1s IF A=Ford
> *AND* B=Focus.
>
> I don't understand how this fits my usual ubderstanding of the ELSE
> clause of an IF statement. And I think it's this stumbling block that's
> stopping me making greater use of such functions.
>
> If anyone could enlighten me I'd really appreciate it?
>
> TIA,
>
> Jason
>


 
Reply With Quote
 
Jay
Guest
Posts: n/a
 
      15th Aug 2006
Ragdyer wrote:
> Besides the fact that you left a comma out of your posted formula, why not
> get in the habit of using the non-array SumProduct() function, which is more
> straight forward for comprehension:
>
> =SUMPRODUCT((A1:A100="Ford")*(B1:B100="Focus"))
>
> And if you have additional criteria to include, simply add another argument:
>
> =SUMPRODUCT((A1:A100="Ford")*(B1:B100="Focus")*(C1:C100="Red"))
>



THanks for this RD, I wasn't aware of the use of SUMPRODUCT as a
multiple argument count function. I agree that it is a lot simpler.

Thanks again,

Jason

 
Reply With Quote
 
 
 
Reply

Thread Tools
Rate This Thread
Rate This Thread:

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
Array formula: how to join 2 ranges together to form one array? Rich_84 Microsoft Excel Worksheet Functions 2 1st Apr 2009 06:38 PM
conversion to formula of string contaning IF clause JeanBQ Microsoft Excel Programming 1 31st Mar 2006 05:49 PM
Tricky array formula issue - Using array formula on one cell, then autofilling down a range aspenbordr Microsoft Excel Programming 0 27th Jul 2005 03:59 PM
Help with And/Or Clause in Formula DoctorV Microsoft Excel Discussion 4 30th Jul 2004 08:36 PM
Array Formula - Use of OFFSET function with array argument Alan Microsoft Excel Worksheet Functions 2 11th Feb 2004 09:38 PM


Features
 

Advertising
 

Newsgroups
 


All times are GMT +1. The time now is 04:34 PM.