+ Reply to Thread
Results 1 to 8 of 8

limited countif

Hybrid View

  1. #1
    Registered User
    Join Date
    04-06-2009
    Location
    Austin, TX
    MS-Off Ver
    Excel 2007
    Posts
    34

    limited countif

    I am trying to get excel to count the following

    Count all fields in column B that have zeros in them but only until the number turns positiv.

    For example

    B1: 0
    B2: 0
    B3: 1000
    B4: 1000
    B5: 1000
    B6: 1000
    B7: 0
    B8: 0

    Ideally my outcome is: 2 and not 4
    Attached Files Attached Files
    Last edited by katja328; 10-23-2009 at 01:06 PM.

  2. #2
    Valued Forum Contributor rwgrietveld's Avatar
    Join Date
    09-02-2008
    Location
    Netherlands
    MS-Off Ver
    XL 2007 / XL 2010
    Posts
    1,671

    Re: limited countif

    Just make the range smaller. Look for the first value that is > 0 with
    =MATCH(1,B3:B15,1)
    Then use indirect to interpret the string
    "$B$3:B"&(2+MATCH(1,B3:B15,1))
    B17 becomes:
    =COUNTIF(INDIRECT("$B$3:B"&(2+MATCH(1,B3:B15,1))),"0")
    Looking for great solutions but hate waiting?
    Seach this Forum through Google

    www.Google.com
    (e.g. +multiple +IF site:excelforum.com/excel-general/ )

    www.Google.com
    (e.g. +fill +combobox site:excelforum.com/excel-programming/ )

    Ave,
    Ricardo

  3. #3
    Registered User
    Join Date
    04-06-2009
    Location
    Austin, TX
    MS-Off Ver
    Excel 2007
    Posts
    34

    Re: limited countif

    What does the 2 stand for?

    This works fine except for when the amounts of free rent are greater than 2. It seems to count one less than is actually there.
    Last edited by katja328; 10-22-2009 at 05:20 PM.

  4. #4
    Valued Forum Contributor rwgrietveld's Avatar
    Join Date
    09-02-2008
    Location
    Netherlands
    MS-Off Ver
    XL 2007 / XL 2010
    Posts
    1,671

    Re: limited countif

    Yoyr range starts from row 3 instead of 1. Therefore I need an offset of 2.

    Can you give an example of the second comment?

  5. #5
    Forum Guru DonkeyOte's Avatar
    Join Date
    10-22-2008
    Location
    Northumberland, UK
    MS-Off Ver
    O365
    Posts
    21,531

    Re: limited countif

    I'm with rwg for approach but would probably opt for non-volatile INDEX over INDIRECT, eg (based on your earlier upload):

    C1: =IF(B3,"",COUNTIF(B3:INDEX(B3:B15,MATCH(1,B3:B15)),0))

  6. #6
    Valued Forum Contributor rwgrietveld's Avatar
    Join Date
    09-02-2008
    Location
    Netherlands
    MS-Off Ver
    XL 2007 / XL 2010
    Posts
    1,671

    Re: limited countif

    Never seen such use of INDEX. I like it.
    Good addition DonkeyOte

  7. #7
    Forum Guru DonkeyOte's Avatar
    Join Date
    10-22-2008
    Location
    Northumberland, UK
    MS-Off Ver
    O365
    Posts
    21,531

    Re: limited countif

    In most cases INDEX can be used in preference to volatiles like OFFSET and INDIRECT... the latter not so when the sheet reference is a dynamic variable. OFFSET is sometimes easier from a syntax perspective but wherever possible I adopt INDEX.
    (should add that INDEX gives impression of being Volatile but in reality is not)

    In short INDEX is incredibly powerful (& flexible) but is also slow if used on large ranges... eg

    =SUM(INDEX((A1:A10000="a")*(B1:B10000="b")*C1:C10000,0))

    is likely to prove slower than a SUMPRODUCT / CSE

    =SUMPRODUCT((A1:A10000="a")*(B1:B10000="b")*C1:C10000)
    =SUM(IF((A1:A10000="a")*(B1:B10000="b"),C1:C10000))) - CSE

  8. #8
    Registered User
    Join Date
    04-06-2009
    Location
    Austin, TX
    MS-Off Ver
    Excel 2007
    Posts
    34

    Cool Re: limited countif

    I went ahead and used this formula on my actual workbook (very different from the sample uploaded). I substituted the 2 for a 3 I am starting in row 4.

    =COUNTIF(INDIRECT("$O$4:O"&(3+MATCH(1,O4:O15,1))),"0")

    This works well for my first calculations on how many months nothing is paid.

    Everything works perfectly until the term ends and the amount reverts back to zero.

    Currently, I am using a simple countif function to count months with the corresponding rate. After the rent term has started, I would like for excel to count the months only if a dollar amount is listed.

    Basically, count the number of months that the amount in O4:O123 is the same as in J21 but do not count if that amount is "0"

    Sorry about this confusion.

+ 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