+ Reply to Thread
Results 1 to 8 of 8

With one simple tweak, CSE formula goes haywire! Is this a bug?

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

    With one simple tweak, CSE formula goes haywire! Is this a bug?

    Hello Everyone,

    I have 1700 company names populating the column of a large table. All the company names are text, without any zero or blank entries. There are, however, many duplicate names in this column.

    I'm doing some analysis that requires me to calculate the number of unique company names. For reasons that are too complex to explain here, it is not appropriate in this situation to filter out, hide or remove the duplicates names (and the rows of data of which they are a part).

    So, I found a lovely little array formula that counts the distinct values in a table column that only contains text entries. In this case, the name of my column is "C7", for column seven. Here's the formula:

    {=SUM(

    1/COUNTIF(Table[C7],Table[C7])

    )}


    This formula returns an intelligent answer of 1135 unique company names.

    I've also realized that I can add a simple little condition that will exclude some specific entries (though not necessarily all instances of that company name) before the number of distinct names is counted. That formula is:

    {=SUM(

    IF(Table[C8]="Yes",

    1/COUNTIF(Table[C7],Table[C7])

    ))}


    The answer now is an intelligent 630, meaning that 630 unique company names remain in the column after removing those entries whose adjacent cell in column C8 is not "Yes".

    Now, here's where things go haywire. If I add a second condition, like this:


    {=SUM(

    IF(Table[C8]="Yes",

    IF(Table[C12]<>0,

    1/COUNTIF(Table[C7],Table[C7])

    )))}


    Suddenly, the answer is a nonsensical 591.9184412 !!!

    How can that be? At a minimum, I expect a whole number answer from this formula! What is happening? Have I stumbled on an Excel bug?

    I look forward to your workarounds and comments!

    Cheers,

    Jay

    PS: I am, however, looking for a single (array) formula that will go into a single cell.
    Last edited by JayUSA; 01-23-2010 at 11:55 PM.

  2. #2
    Forum Expert darkyam's Avatar
    Join Date
    03-05-2008
    Location
    Houston, TX
    MS-Off Ver
    2013
    Posts
    2,191

    Re: With one simple tweak, CSE formula goes haywire! Is this a bug?

    Have you tried {=SUM(IF(AND(Table[C8]="Yes",Table[C12]<>0),1/COUNTIF(Table[C7],Table[C7])))}

  3. #3
    Forum Expert NBVC's Avatar
    Join Date
    12-06-2006
    Location
    Mississauga, CANADA
    MS-Off Ver
    2003:2010
    Posts
    34,898

    Re: With one simple tweak, CSE formula goes haywire! Is this a bug?

    Try:

    =COUNT(1/FREQUENCY(IF(Table[C8]="yes",IF(Table[C12]<>0,MATCH(Table[C7],Table[C7],0))),ROW(Table[C7])-ROW(OFFSET(Table[C7],0,0,1,1))+1))

    confirmed with CSE
    Where there is a will there are many ways.

    If you are happy with the results, please add to the contributor's reputation by clicking the reputation icon (star icon) below left corner

    Please also mark the thread as Solved once it is solved. Check the FAQ's to see how.

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

    Re: With one simple tweak, CSE formula goes haywire! Is this a bug?

    Hi Everyone,

    I'm attaching a subset of the full spreadsheet to illustrate this strange behavior!

    Also, thanks darkyam... I plugged your formula into the attached spreadsheet, but got zero fan an answer.

    Please take a look... and keep the ideas coming!

    Cheers,

    Jay
    Attached Files Attached Files

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

    Re: With one simple tweak, CSE formula goes haywire! Is this a bug?

    NBVC and darkyam,

    YOU GUYS ARE THE BEST!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!

    NBVC's formula worked perfectly! But I also appreciate darkyam's effort to get the ball rolling!!

    How you guys can read, understand, solve and answer a post like mine -- so quickly!! -- is way beyond me.

    Eternal thanks!

    Cheers,

    Jay

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

    Re: With one simple tweak, CSE formula goes haywire! Is this a bug?

    If as it seems you're using XL2007 you could perhaps use a non-volatile SUMPRODUCT with COUNTIFS

    Please Login or Register  to view this content.
    Given your file has external links - I can't really test the above against NBVC's meaningfully...

    Points:

    SUMPRODUCT is not really more efficient than a CSE Array { } however it does not require Array entry so some people consider it preferable from end-user perspective

    The main bonus in this instance is that the above approach is non-volatile which is a very good thing when it comes to Arrays/Sumproducts ... however unlike the earlier Frequency Array it would not (given use of COUNTIFS) be backwards compatible with earlier version of XL should that be a concern.
    You could still make a non-volatile backwards compatible SUMPRODUCT but if not required I'd advocate above in first instance.

  7. #7
    Forum Expert NBVC's Avatar
    Join Date
    12-06-2006
    Location
    Mississauga, CANADA
    MS-Off Ver
    2003:2010
    Posts
    34,898

    Re: With one simple tweak, CSE formula goes haywire! Is this a bug?

    If the formula is being used once or twice in the sheet as per sample, then does volatility really affect it much?

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

    Re: With one simple tweak, CSE formula goes haywire! Is this a bug?

    Well that would depend not only on volume & nature of the Volatile calcs but also on the frequency of Volatile actions undertaken in the model...
    (unless of course one opted for Manual Calc but I'd always view that as method of last resort - others don't necessarily have the same opinion)

+ 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