+ Reply to Thread
Results 1 to 5 of 5

Thread: If and Countif treat blanks differently?

  1. #1
    Registered User
    Join Date
    02-07-2012
    Location
    NJ, USA
    MS-Off Ver
    Excel 2007
    Posts
    19

    If and Countif treat blanks differently?

    Hi,
    I am learning to use Excel 2007. I get different results using IF() and Countif() in a situation where I expect them to behave the same. Suppose I have a sheet called "green status pivot" It contains a pivot table. The pivot table contains some numbers (each number is either a "0" or a "1") and some blanks (empty cells in the pivot table because the underlying data has missing values). I want to count the number of cells with value "0" (as opposed to value "1" or missing value).

    Suppose I have an empty cell in a cell O20 in that sheet with the pivot table. If I do =COUNTIF('green status pivot'!O20, " = 0") I get 0, but if I do = IF('green status pivot'!O3 =0, 1,0) I get 1. Is this supposed to happen (if so, is there some underlying logic?) or am I messing up something? Is there some way to specify to Excel how to treat blanks (missing values) in IF() and in Countif()?

    Many thanks.
    Studiosa

  2. #2
    Forum Guru Bob Phillips's Avatar
    Join Date
    09-03-2005
    Location
    Wessex
    MS-Off Ver
    MS Excel 2010
    Posts
    2,247

    Re: If and Countif treat blanks differently?

    How about =COUNTIF('green status pivot'!O20, " 0")

  3. #3
    Registered User
    Join Date
    02-07-2012
    Location
    NJ, USA
    MS-Off Ver
    Excel 2007
    Posts
    19

    Re: If and Countif treat blanks differently?

    Hi,
    Thank you very much for your reply.
    Actually countif(range,0") does exactly the same as countif(range, "=0")


    Studiosa.

  4. #4
    Valued Forum Contributor Pete_UK's Avatar
    Join Date
    12-31-2011
    Location
    Warrington, England
    MS-Off Ver
    Excel 2007
    Posts
    685

    Re: If and Countif treat blanks differently?

    This counts blanks:

    =COUNTIF(A1:A10,"=")

    this counts non-blanks:

    =COUNTIF(A1:A10,"<>")

    (where the extra "" is redundant), and this counts zeros:

    =COUNTIF(A1:A10,"0")

    (where the = is implied).

    Hope this helps.

    Pete

  5. #5
    Registered User
    Join Date
    02-07-2012
    Location
    NJ, USA
    MS-Off Ver
    Excel 2007
    Posts
    19

    Re: If and Countif treat blanks differently?

    Pete,
    This was very helpful, thank you. I also discovered a command specifically for counting blanks: =COUNTBLANK(A1:A10)

    studiosa

+ 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.2.0