+ Reply to Thread
Results 1 to 8 of 8

Conditional count

  1. #1
    Registered User
    Join Date
    06-20-2010
    Location
    US
    MS-Off Ver
    Excel 2007
    Posts
    4

    Conditional count

    x y
    a 11
    b 11
    c 11
    a 12
    c 12
    d 12
    a 13
    b 13
    d 13

    I want to find out how many times a and b are together for all values of y. For example in the above table a and b are together 2 times i.e. when y=11 and y=13 you have a and b in the x column. I want the count of when a and b are together. I have a database consisting of more than 100,000 lines. Please help

  2. #2
    Forum Expert teylyn's Avatar
    Join Date
    10-28-2008
    Location
    New Zealand
    MS-Off Ver
    Excel 365 Insider Fast
    Posts
    11,372

    Re: Conditional count

    Hello kaushiksarda,

    you can use a formula like

    =SUMPRODUCT(--(A1:A100="a"),--(A2:A101="b"))

    Note that both arrays have 100 rows, but the first array starts in row 1 and the second array starts in row 2. This will deliver a count of the rows where a is immediately followed by b.

    Does that help?

    cheers

  3. #3
    Registered User
    Join Date
    06-20-2010
    Location
    US
    MS-Off Ver
    Excel 2007
    Posts
    4

    Re: Conditional count

    Quote Originally Posted by teylyn View Post
    Hello kaushiksarda,

    you can use a formula like

    =SUMPRODUCT(--(A1:A100="a"),--(A2:A101="b"))

    Note that both arrays have 100 rows, but the first array starts in row 1 and the second array starts in row 2. This will deliver a count of the rows where a is immediately followed by b.

    Does that help?

    cheers
    Hi,

    Want I want is to find out the count for occurrence of a and b together for unique values of y.

    When y=11 a and b have a occurrence. When y = 13 a and b have another occurrence.

    b is not always followed after a. Is there some way we can do this. the sum product formula does not work.

  4. #4
    Forum Expert ConneXionLost's Avatar
    Join Date
    03-11-2009
    Location
    Victoria, Canada
    MS-Off Ver
    2010
    Posts
    2,952

    Re: Conditional count

    How about this:

    Please Login or Register  to view this content.
    Cheers,
    Would you like to say thanks? Please click the: " Add Reputation" button, on the grey bar below the post.

  5. #5
    Forum Expert
    Join Date
    04-14-2009
    Location
    Taiwan
    MS-Off Ver
    Excel 2016,2019,O365
    Posts
    2,014

    Re: Conditional count

    Try this,

    Please Login or Register  to view this content.
    committed with Ctrl+Shift+Enter

    HTH,
    windknife

  6. #6
    Registered User
    Join Date
    06-20-2010
    Location
    US
    MS-Off Ver
    Excel 2007
    Posts
    4

    Re: Conditional count

    Thanks man,

    your formula works.. it was a great help


    Quote Originally Posted by windknife View Post
    Try this,

    Please Login or Register  to view this content.
    committed with Ctrl+Shift+Enter

    HTH,
    windknife

  7. #7
    Registered User
    Join Date
    06-20-2010
    Location
    US
    MS-Off Ver
    Excel 2007
    Posts
    4

    Re: Conditional count

    Quote Originally Posted by kaushiksarda View Post
    Thanks man,

    your formula works.. it was a great help
    Hello again,

    the formula works perfectly but my dataset has 200,000 lines and excel produces an error saying excel ran out of resources while attempting to calculate one or more formulas. IS there any way around it.

  8. #8
    Forum Expert
    Join Date
    04-14-2009
    Location
    Taiwan
    MS-Off Ver
    Excel 2016,2019,O365
    Posts
    2,014

    Re: Conditional count

    Maybe use tow help columns to deal with it.

    1. select C1:C20000
    =IF($A$1:$A20000="a",$B$1:$B20000,"")
    committed with CSE
    2. select D1:D20000
    =IF($A$1:$A20000="b",$B$1:$B20000,"")
    committed with CSE
    3. E1
    Please Login or Register  to view this content.
    committed with CSE.

    HTH,
    windknife

    A small sample is attached .
    Attached Files Attached Files

+ 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