#1   Report Post  
Mike Fogleman
 
Posts: n/a
Default (--(Function))

I have seen the use of (--) in formulas on this NG. What is it's purpose and
applications?
Curious to learn..
Mike F


  #2   Report Post  
Bob Phillips
 
Posts: n/a
Default

Hi Mike,

Take a look at http://www.xldynamic.com/source/xld.SUMPRODUCT.html for more
than youn ever thought you needed :-)

--

HTH

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


"Mike Fogleman" wrote in message
...
I have seen the use of (--) in formulas on this NG. What is it's purpose

and
applications?
Curious to learn..
Mike F




  #3   Report Post  
Jason Morin
 
Posts: n/a
Default

Mike-

This technique was popularized by Harlan Grove in
converting arrays of booleans to 1's and 0's when working
with arrays in formulas. I think it's best explained
through an example. Imagine this list in A1:A5:

eat
easy
tree
elephant
car

We want to count the number of words beginning with the
letter "e". We could use the formula:

=SUMPRODUCT(--(LEFT(A1:A5)="e"))

This formula evaluates the first letter of each cell in
the range and equates it to "e". If you select that
portion of the formula and press F9, you would see:

=SUMPRODUCT(--({TRUE;TRUE;FALSE;TRUE;FALSE}))

Unfortunately, we can't sum these booleans in this way,
so we use the double dash (actually it's referred to as
double unary I believe) to convert the booleans first to
all negatives:

=SUMPRODUCT(-{-1;-1;0;-1;0})

and the second one to convert them back to positive. The
0's are not affected. So you end up with:

=SUMPRODUCT({1;1;0;1;0})

which equals 3.

It should be noted that there are other methods. You can
also multiply by 1, add 0, use the power of 1, or use the
N function to convert the array of booleans.

=SUMPRODUCT(1*(LEFT(A1:A5)="e"))
=SUMPRODUCT(0+(LEFT(A1:A5)="e"))
=SUMPRODUCT(N(LEFT(A1:A5)="e"))
=SUMPRODUCT((LEFT(A1:A5)="e")^1)

Determining which formula is most efficient of all of
these is an argument for another day.

HTH
Jason
Atlanta, GA




-----Original Message-----
I have seen the use of (--) in formulas on this NG. What

is it's purpose and
applications?
Curious to learn..
Mike F


.

Reply
Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes

Posting Rules

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


Similar Threads
Thread Thread Starter Forum Replies Last Post
Formula to list unique values JaneC Excel Worksheet Functions 4 December 10th 04 12:25 AM
I cant use englisch function names in a swedich version of excel PE Excel Discussion (Misc queries) 2 December 7th 04 01:00 AM
Find a Function to use accross different worksheets R. Hale Excel Worksheet Functions 3 November 25th 04 07:07 AM
change function variable prompts?? thinkingfield Excel Worksheet Functions 1 November 8th 04 04:01 PM
Counting Function Dilemma Simon Lloyd Excel Worksheet Functions 0 November 8th 04 03:13 PM


All times are GMT +1. The time now is 06:08 AM.

Powered by vBulletin® Copyright ©2000 - 2025, Jelsoft Enterprises Ltd.
Copyright ©2004-2025 ExcelBanter.
The comments are property of their posters.
 

About Us

"It's about Microsoft Excel"