+ Reply to Thread
Results 1 to 7 of 7

Count instances where the difference between two columns is a specific value

  1. #1
    Forum Contributor
    Join Date
    04-26-2009
    Location
    Austin, TX
    MS-Off Ver
    Excel 2016
    Posts
    241

    Count instances where the difference between two columns is a specific value

    Hi Everyone,

    I seem to have forgotten my advanced Excel / CSE magic!

    I have two columns of numeric data: A1-A20 and B1-B20

    I want to COUNT (not sum) the number of times that:

    the A value in the column, less the corresponding B value beside it, is exactly 3

    PROVIDED that both A and the B values are positive (i.e. greater than zero).


    Any suggestions, folks?

    Cheers,

    Jay
    Last edited by JayUSA; 06-20-2012 at 07:24 PM. Reason: Fixed typo

  2. #2
    Forum Guru
    Join Date
    08-05-2004
    Location
    NJ
    MS-Off Ver
    365
    Posts
    13,582

    Re: Count instances of where the difference between two columns is a specific value

    Try

    =SUMPRODUCT(--(B1:B20-A1:A20=3))
    ChemistB
    My 2?

    substitute commas with semi-colons if your region settings requires
    Don't forget to mark threads as "Solved" (Edit First post>Advanced>Change Prefix)
    If I helped, Don't forget to add to my reputation (click on the little star at bottom of this post)

    Forum Rules: How to use code tags, mark a thread solved, and keep yourself out of trouble

  3. #3
    Forum Expert mrice's Avatar
    Join Date
    06-22-2004
    Location
    Surrey, England
    MS-Off Ver
    Excel 2013
    Posts
    4,967

    Re: Count instances of where the difference between two columns is a specific value

    Try this array formula

    =SUM(IF(A1:A20-B1:B20=3,IF(A1:A20>0,IF(B1:B20>0,1,0),0),0))

    Remember to press control- shift - enter when entering this into an empty cell.
    Martin

  4. #4
    Forum Contributor
    Join Date
    04-26-2009
    Location
    Austin, TX
    MS-Off Ver
    Excel 2016
    Posts
    241

    Re: Count instances of where the difference between two columns is a specific value

    Well... I reversed the subtraction logic to comply with scenario I was trying to describe, giving:

    =SUMPRODUCT(--(A1:A20-B1:B20=3))

    However, in my spreadsheet, this formula incorrectly counts cell pairs of difference =3, even when the A or B value is blank.

    Thus two A/B cell pairs of:

    3 [blank]
    [blank] -3

    will yield a count of 2, where it should yield a count of zero.

    Perhaps a further tweak will make it work as I am hoping?

    Cheers,

    Jay
    Last edited by JayUSA; 06-20-2012 at 01:25 PM.

  5. #5
    Forum Guru
    Join Date
    08-05-2004
    Location
    NJ
    MS-Off Ver
    365
    Posts
    13,582

    Re: Count instances of where the difference between two columns is a specific value

    Okay, try this

    =SUMPRODUCT(--(A1:A20-B1:B20=3), --(A1:A20<>0),--(B1:B20<>0))

  6. #6
    Forum Contributor
    Join Date
    04-26-2009
    Location
    Austin, TX
    MS-Off Ver
    Excel 2016
    Posts
    241

    Re: Count instances of where the difference between two columns is a specific value

    Yes, that works beautifully!
    Last edited by JayUSA; 06-20-2012 at 09:37 PM. Reason: I made a mistake.

  7. #7
    Forum Contributor
    Join Date
    04-26-2009
    Location
    Austin, TX
    MS-Off Ver
    Excel 2016
    Posts
    241

    Re: Count instances of where the difference between two columns is a specific value

    [My error.]
    Last edited by JayUSA; 06-20-2012 at 09:37 PM.

+ 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