+ Reply to Thread
Results 1 to 4 of 4

What does the "--" do?

  1. #1
    Registered User
    Join Date
    12-05-2005
    Posts
    13

    What does the "--" do?

    First off, I wasn't sure where to post this because I didn't know if the -- is classified as a worksheet function or not, but what does it do? I've seen them in a bunch of posts. I am just curious what they do.

    Example:

    =SUMPRODUCT(--($D$1:$D$100="100"),$F$1:$F$100)

    versus

    =SUMPRODUCT(($D$1:$D$100="100"),$F$1:$F$100)

    Why does the second one not work?

    Thanks,
    Nick

  2. #2
    Dave Peterson
    Guest

    Re: What does the "--" do?

    -- can be used to convert non-numerics to numbers.

    If A1 contained the text '123, then
    =--A1 will contian the number 123.

    It also can be used to convert True/False to +1/0. (-true = -1, --true = +1)

    =sumproduct() likes to work with numbers so the first formula gets those
    trues/falses converted to 1/0s.

    But you can also write the formula this way:
    =SUMPRODUCT(($D$1:$D$100="100")*($F$1:$F$100))

    Just the act of multiplying is enough to coerce the true/false to 1/0.

    =0+A1
    =1*a1
    will do the same kind of thing in that first example.

    thekovinc wrote:
    >
    > First off, I wasn't sure where to post this because I didn't know if the
    > -- is classified as a worksheet function or not, but what does it do?
    > I've seen them in a bunch of posts. I am just curious what they do.
    >
    > Example:
    >
    > =SUMPRODUCT(--($D$1:$D$100="100"),$F$1:$F$100)
    >
    > versus
    >
    > =SUMPRODUCT(($D$1:$D$100="100"),$F$1:$F$100)
    >
    > Why does the second one not work?
    >
    > Thanks,
    > Nick
    >
    > --
    > thekovinc
    > ------------------------------------------------------------------------
    > thekovinc's Profile: http://www.excelforum.com/member.php...o&userid=29378
    > View this thread: http://www.excelforum.com/showthread...hreadid=490898


    --

    Dave Peterson

  3. #3
    Registered User
    Join Date
    12-05-2005
    Posts
    13
    Thank you very much!

  4. #4
    Roger Govier
    Guest

    Re: What does the "--" do?

    Hi Nick

    The double unary minus "--" coerces the TRUE or FALSE result of the
    comparison inside the first set of brackets into 1's or 0's. This could also
    be achieved by adding +0 or multiplying with a *1 addition to the formula
    but doing a minus, minus (which comes back to the original value) is a
    little faster in execution.

    The resulting 1's and 0's then multiply the array from the second range and
    Sumproduct adds the results to give the final answer.

    So if the value in cell D1 were 100, that would be TRUE, and coerced to 1
    would be multiplied by the value in F1 would result in the value in F1.
    If D2 were not 100, then it would be FALSE hence 0 which multiplying by the
    value in F2 would result in 0.


    Regards

    Roger Govier


    thekovinc wrote:
    > First off, I wasn't sure where to post this because I didn't know if the
    > -- is classified as a worksheet function or not, but what does it do?
    > I've seen them in a bunch of posts. I am just curious what they do.
    >
    > Example:
    >
    > =SUMPRODUCT(--($D$1:$D$100="100"),$F$1:$F$100)
    >
    > versus
    >
    > =SUMPRODUCT(($D$1:$D$100="100"),$F$1:$F$100)
    >
    > Why does the second one not work?
    >
    > Thanks,
    > Nick
    >
    >


+ Reply to Thread

Thread Information

Users Browsing this Thread

There are currently 1 users browsing this thread. (0 members and 1 guests)

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts

Search Engine Friendly URLs by vBSEO 3.6.0 RC 1