+ Reply to Thread
Results 1 to 4 of 4

Counting Unique Occurences in a Range

Hybrid View

  1. #1
    Forum Contributor
    Join Date
    07-13-2007
    Posts
    151

    Counting Unique Occurences in a Range

    I found the following formula in another post that provides one with the ability to count the unique occurences of a text string in a range.

    =SUMPRODUCT(1/COUNTIF(A1:A20,A1:A20))

    I also found the following modification to account for the situation where some cells in the range may be blank:

    =SUMPRODUCT((A1:A20<>"")/COUNTIF(A1:A20,A1:A20&""))

    Both of these work well for me, but I don't understand WHY they work. I feel that I have a good understanding of using SUMPRODUCT with multiple condition tests using the * operator for example, but I'm not understanding why the formulas above give the correct answers.

    Is there someone out there that could explain in simple terms what these formulas are doing so as to help me understand the WHY in this case? It would be most apreciated.

    Thanks in advance.

    Shred

  2. #2
    Forum Contributor
    Join Date
    03-13-2005
    Posts
    6,195
    Quote Originally Posted by ShredDude
    I found the following formula in another post that provides one with the ability to count the unique occurences of a text string in a range.

    =SUMPRODUCT(1/COUNTIF(A1:A20,A1:A20))

    I also found the following modification to account for the situation where some cells in the range may be blank:

    =SUMPRODUCT((A1:A20<>"")/COUNTIF(A1:A20,A1:A20&""))

    Both of these work well for me, but I don't understand WHY they work. I feel that I have a good understanding of using SUMPRODUCT with multiple condition tests using the * operator for example, but I'm not understanding why the formulas above give the correct answers.

    Is there someone out there that could explain in simple terms what these formulas are doing so as to help me understand the WHY in this case? It would be most apreciated.

    Thanks in advance.

    Shred
    Hi,

    http://www.xldynamic.com/source/xld.SUMPRODUCT.html is the best place to have the Sumproduct explained, but for your question, if an item occurs two times, then 1 is divided by two, two times, and two halves added to give one.

    If the product occurs 3 times then 1 is divided by 3, 3 times, and the 3 x .33 added to give one.

    hth
    ---
    Si fractum non sit, noli id reficere.

  3. #3
    Forum Expert daddylonglegs's Avatar
    Join Date
    01-14-2006
    Location
    England
    MS-Off Ver
    Microsoft 365
    Posts
    14,719
    hello Shred,

    I wouldn't say this was "in simple terms" but if you want a definitive explanation of the second formula see Aladin Akyurek's explanation here

  4. #4
    Forum Contributor
    Join Date
    07-13-2007
    Posts
    151

    Thanks!

    Thanks to both of you. I hadn't iterated through the division. In my mind I was just iterating through the COUNTIF....

    I get it now.

    Thanks again.

+ 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