+ Reply to Thread
Results 1 to 33 of 33

Counting uniques

  1. #1
    Registered User
    Join Date
    12-17-2014
    Location
    London
    MS-Off Ver
    Excel 2007
    Posts
    12

    Post Counting uniques

    As you can see I am new in the forum, I am really happy to join and learn from you, and also give some of my short experience to other users

    The "problem" I am bringing you today is this snapshot of a huge list that I've got, basically I would like come with a formula to count the number of different cities that every single person has visited...

    I have to avoid using Pivot Tables,filters, removing manually duplicates or any other workarounds, just a "simple" formula that I can extend to the rest of the list

    I am trying with sumproduct + countif and countifs, but I don't manage to arrive to the correct formula, maybe anyone can help?

    Thank you very much!
    Muchas gracias!
    Attached Files Attached Files

  2. #2
    Forum Guru samba_ravi's Avatar
    Join Date
    07-26-2011
    Location
    Hyderabad, India
    MS-Off Ver
    Excel 2021
    Posts
    8,914

    Re: Counting uniques

    G11=SUM(INDEX(($A$3:$A$21=$F11)/COUNTIFS($A$3:$A$21,$A$3:$A$21,$B$3:$B$21,$B$3:$B$21),0))
    Copy towards down
    Samba

    Say thanks to those who have helped you by clicking Add Reputation star.

  3. #3
    Registered User
    Join Date
    12-17-2014
    Location
    London
    MS-Off Ver
    Excel 2007
    Posts
    12

    Re: Counting uniques

    Hi!!

    Wow! thanks!! that is very helpful!!!

    The only thing will be that... Do you think is there any way to simplify the formula? my original file has 87000 rows, and once I entered your formula my Excel crashes... (I think I am not messing up with the formula...but I need to double check... the thing is I dont get any error after entering the formula, it's just the computer starts "thinking" and excel says "not responding")

    Thanks again!


    Correction: I am not transfering your formula wrongly, just tried for a range of 100 rows and it worked perfectly, but the moment I try to extend it for 87000rows, my computer crashes... LOL,,, thats why maybe I am wondering maybe there is a way to simplify the formula?
    Last edited by mglon; 12-17-2014 at 08:36 AM.

  4. #4
    Forum Expert XOR LX's Avatar
    Join Date
    04-18-2013
    Location
    Turin, Italy
    MS-Off Ver
    Office 365
    Posts
    7,742

    Re: Counting uniques

    Hi.

    I'm not certain, though it's possible that this alternative construction, an array formula**, offers slightly better performance over large datasets:

    =SUM(IF(FREQUENCY(IF($A$3:$A$21=J11,MATCH($B$3:$B$21,$B$3:$B$21,0)),ROW($B$3:$B$21)-MIN(ROW($B$3:$B$21))+1),1))

    Regards


    **Array formulas are not entered in the same way as 'standard' formulas. Instead of pressing just ENTER, you first hold down CTRL and SHIFT, and only then press ENTER. If you've done it correctly, you'll notice Excel puts curly brackets {} around the formula (though do not attempt to manually insert these yourself).
    Click * below if this answer helped

    Advanced Excel Techniques: http://excelxor.com/

  5. #5
    Registered User
    Join Date
    12-17-2014
    Location
    London
    MS-Off Ver
    Excel 2007
    Posts
    12

    Re: Counting uniques

    Hi Xor LX!

    I am afraid, the performance hasn't improved, I am checking the PC stats and while it's processing the formula my CPU usage goes to 100%, grr... need a new computer or find another workaround...

    thanks for your contribution so far, I really appreciate, if you have any other ideas I will be more than happy to test them!

    Thanks!
    Gracias!

  6. #6
    Forum Expert XOR LX's Avatar
    Join Date
    04-18-2013
    Location
    Turin, Italy
    MS-Off Ver
    Office 365
    Posts
    7,742

    Re: Counting uniques

    Interesting.

    And do you have many other formulas in there besides this series?

    I did an experiment where I extended the range to row 85000. Using nflsales' formula, my workbook crashed. Using the version I posted, however, and for the six names as given, full calculation took just under 0.5 seconds.

    Regards

  7. #7
    Forum Expert XOR LX's Avatar
    Join Date
    04-18-2013
    Location
    Turin, Italy
    MS-Off Ver
    Office 365
    Posts
    7,742

    Re: Counting uniques

    @nflsales

    Surprising how vastly inefficient that set-up with COUNTIFS is, actually.

    You'd think it would be the other way round, though the combination of FREQUENCY and MATCH is evidently a very fast one in terms of processing.

    Regards

  8. #8
    Registered User
    Join Date
    12-17-2014
    Location
    London
    MS-Off Ver
    Excel 2007
    Posts
    12

    Re: Counting uniques

    And do you have many other formulas in there besides this series?
    not yet, but eventually there will be, but way more simple like A2xA3 or similars, they shouldn't go as crazy as this one...

    I did an experiment where I extended the range to row 85000. Using nflsales' formula, my workbook crashed. Using the version I posted, however, and for the six names as given, full calculation took just under 0.5 seconds.
    Really? maybe am I doing something wrong? I tried yours on the sample and it worked straight away, and after adapting yours to the big file I got CPU usage over 100% and Crashed, I have an i5 and excel 2007,,, humm

  9. #9
    Forum Expert XOR LX's Avatar
    Join Date
    04-18-2013
    Location
    Turin, Italy
    MS-Off Ver
    Office 365
    Posts
    7,742

    Re: Counting uniques

    And to how many rows did you copy that formula?

    And I take it you deleted nflsales' formulas first!!

    Regards

  10. #10
    Registered User
    Join Date
    12-17-2014
    Location
    London
    MS-Off Ver
    Excel 2007
    Posts
    12

    Re: Counting uniques

    to 87174 rows like a boss... hehe

  11. #11
    Registered User
    Join Date
    12-17-2014
    Location
    London
    MS-Off Ver
    Excel 2007
    Posts
    12

    Re: Counting uniques

    and thats probably why its crashing...

  12. #12
    Forum Expert XOR LX's Avatar
    Join Date
    04-18-2013
    Location
    Turin, Italy
    MS-Off Ver
    Office 365
    Posts
    7,742

    Re: Counting uniques

    Quote Originally Posted by mglon View Post
    to 87174 rows like a boss... hehe
    ???

    I thought it was the data source that was that number of rows? And that you only had a dozen names or so, i.e. a dozen rows' worth of formulas?

    Regards

  13. #13
    Registered User
    Join Date
    12-17-2014
    Location
    London
    MS-Off Ver
    Excel 2007
    Posts
    12

    Re: Counting uniques

    oh sorry, I think I didn't understand your question

    I copied the formula over 52 rows (52 individual names) and the source data is 87000 Rows

  14. #14
    Forum Expert XOR LX's Avatar
    Join Date
    04-18-2013
    Location
    Turin, Italy
    MS-Off Ver
    Office 365
    Posts
    7,742

    Re: Counting uniques

    Just extended mine to 52 rows. Just over a second for full calculation with the formulas referencing a range of 85,000 rows.

    Perhaps you'll have to replace any confidential information with dummy data and upload your actual workbook.

    Regards

  15. #15
    Registered User
    Join Date
    12-17-2014
    Location
    London
    MS-Off Ver
    Excel 2007
    Posts
    12

    Re: Counting uniques

    Thanks for your suggestion that might help if I keep struggling... just as a quick test, can you attach your last file the one with 52rows and 85krange?

  16. #16
    Forum Expert XOR LX's Avatar
    Join Date
    04-18-2013
    Location
    Turin, Italy
    MS-Off Ver
    Office 365
    Posts
    7,742

    Re: Counting uniques

    Sorry - you don't believe my statements re calculation times in my workbook?

    Regards

  17. #17
    Registered User
    Join Date
    12-17-2014
    Location
    London
    MS-Off Ver
    Excel 2007
    Posts
    12

    Re: Counting uniques

    of course I do!

    just wanted to try your file on my laptop, I am starting to question myself that it might be a limitation of my Excel 2007 I can see that you are using 2010,

    and also if I try yours and I can't run it, at least I will have my peace in mind that I am not doing anything wrong

    is nothing about questionining the calculation times of your workbook, as I said is about questioning me, my computer and my method

    sorry if you took it in the wrong way, it was not my intention at all.

    mglon,

  18. #18
    Forum Expert Tony Valko's Avatar
    Join Date
    12-31-2011
    Location
    Pittsburgh
    MS-Off Ver
    2002, 2007:2013
    Posts
    18,890

    Re: Counting uniques

    Quote Originally Posted by XOR LX View Post
    @nflsales

    Surprising how vastly inefficient that set-up with COUNTIFS is, actually.

    You'd think it would be the other way round, though the combination of FREQUENCY and MATCH is evidently a very fast one in terms of processing.
    In addition, folks also think that the SUM(IF(FREQUENCY is an array formula therefore it must be slower to calculate.

    Not true!
    Biff
    Microsoft MVP Excel
    Keep It Simple Stupid

    Let's Go Pens. We Want The Cup.

  19. #19
    Forum Expert XOR LX's Avatar
    Join Date
    04-18-2013
    Location
    Turin, Italy
    MS-Off Ver
    Office 365
    Posts
    7,742

    Re: Counting uniques

    Quote Originally Posted by Tony Valko View Post
    In addition, folks also think that the SUM(IF(FREQUENCY is an array formula therefore it must be slower to calculate.

    Not true!
    True in general, but with a preceding conditional clause, i.e.:

    SUM(IF(FREQUENCY(IF($A$2:$A$84999=F2,...

    as here, it must be committed with CSE.

    Cheers

  20. #20
    Forum Expert Tony Valko's Avatar
    Join Date
    12-31-2011
    Location
    Pittsburgh
    MS-Off Ver
    2002, 2007:2013
    Posts
    18,890

    Re: Counting uniques

    There is calculation timer code here:

    http://msdn.microsoft.com/en-us/library/aa730921.aspx

    You can run the tests and see for yourself. I do this kind of testing quite often.

    Counting uniques in Excel is "slow" by computing standards, especially on large datasets.

    In general, the SUM(IF(FREQUENCY syntax is faster to calculate compared to other formula syntaxes.

    There are UDFs that are amazingly fast at this but you either have to know how to write (program) them or get them through add-ins.

  21. #21
    Forum Expert XOR LX's Avatar
    Join Date
    04-18-2013
    Location
    Turin, Italy
    MS-Off Ver
    Office 365
    Posts
    7,742

    Re: Counting uniques

    @mglon

    Unfortunately it exceeded forum limits at 80,000 rows. Have attached a version with 50,000 rows worth of data.

    Regards
    Attached Files Attached Files

  22. #22
    Forum Expert XOR LX's Avatar
    Join Date
    04-18-2013
    Location
    Turin, Italy
    MS-Off Ver
    Office 365
    Posts
    7,742

    Re: Counting uniques

    Quote Originally Posted by Tony Valko View Post
    In general, the SUM(IF(FREQUENCY syntax is faster to calculate compared to other formula syntaxes.
    And, as I said, much, much quicker than the equivalent 1/COUNTIFS set-up, which is horrendously slow!

  23. #23
    Forum Expert Tony Valko's Avatar
    Join Date
    12-31-2011
    Location
    Pittsburgh
    MS-Off Ver
    2002, 2007:2013
    Posts
    18,890

    Re: Counting uniques

    Quote Originally Posted by XOR LX View Post
    True in general, but with a preceding conditional clause, i.e.:

    SUM(IF(FREQUENCY(IF($A$2:$A$84999=F2,...

    as here, it must be committed with CSE.
    Yeah, I wasn't claiming the formula wasn't an array entered formula.

    I meant that just because it is an array entered formula doesn't mean it's automatically slower to calculcate compared to a non-array entered formula.

  24. #24
    Forum Expert XOR LX's Avatar
    Join Date
    04-18-2013
    Location
    Turin, Italy
    MS-Off Ver
    Office 365
    Posts
    7,742

    Re: Counting uniques

    Quote Originally Posted by Tony Valko View Post
    Yeah, I wasn't claiming the formula wasn't an array entered formula.

    I meant that just because it is an array entered formula doesn't mean it's automatically slower to calculcate compared to a non-array entered formula.
    Ah - sorry! Then yes - totally agreed! Array formulas are evil monsters which, unless stopped, will take over the internal workings of the world's computer nexus and reduce our state of technological advancement to little more than that of the neanderthals.

  25. #25
    Forum Moderator Glenn Kennedy's Avatar
    Join Date
    07-08-2012
    Location
    Digital Nomad... occasionally based in Ireland.
    MS-Off Ver
    O365 (PC) V 2403
    Posts
    44,009

    Re: Counting uniques

    ...and all I thought we had to fret about was the merged cell...
    Glenn




    None of us get paid for helping you... we do this for fun. So DON'T FORGET to say "Thank You" to all who have freely given some of their time to help YOU.

    Temporary addition of accented to illustrate ongoing problem to the TT: L? fh?ile P?draig sona dhaoibh

  26. #26
    Forum Expert XOR LX's Avatar
    Join Date
    04-18-2013
    Location
    Turin, Italy
    MS-Off Ver
    Office 365
    Posts
    7,742

    Re: Counting uniques

    Perhaps an array formula in a merged cell is the ultimate Excel chimera?

  27. #27
    Forum Moderator Glenn Kennedy's Avatar
    Join Date
    07-08-2012
    Location
    Digital Nomad... occasionally based in Ireland.
    MS-Off Ver
    O365 (PC) V 2403
    Posts
    44,009

    Re: Counting uniques

    I'll never set foot outdoors again...

  28. #28
    Registered User
    Join Date
    12-17-2014
    Location
    London
    MS-Off Ver
    Excel 2007
    Posts
    12

    Re: Counting uniques

    @Xor,

    Just realised that I wasn't pasting in array formulas properly,,, (upss...) maybe that was what was crashing my computer?

    I am looking in to google, but I am getting confused with F2 and paste... can you explain me for "noobs" how to paste the array formula in your file to the 52 rows?

    Thanks!
    Gracias!

  29. #29
    Forum Expert XOR LX's Avatar
    Join Date
    04-18-2013
    Location
    Turin, Italy
    MS-Off Ver
    Office 365
    Posts
    7,742

    Re: Counting uniques

    You only paste it into the first cell, then follow my previous instructions on how to commit it as an array formula, and then copy it down.

    Regards

  30. #30
    Registered User
    Join Date
    12-17-2014
    Location
    London
    MS-Off Ver
    Excel 2007
    Posts
    12

    Re: Counting uniques

    Hi!

    @Xor, following your advice I am uploading my file with dummy data, you will see in the first tab where I want to place the formula, as soon as I do it (place = and the ctr shift enter) computer collapses , and that just for only the first cell! hope you are able to spot where I am failing !


    Thanks guys!

    Ps, I had to zip the file because of the size of it and forum limitations
    Ps, also I deleted everything after row 50k
    Attached Files Attached Files

  31. #31
    Forum Expert XOR LX's Avatar
    Join Date
    04-18-2013
    Location
    Turin, Italy
    MS-Off Ver
    Office 365
    Posts
    7,742

    Re: Counting uniques

    Sincere apologies.

    The data I used for testing was not a fair sample, as the dummy values I entered in the City column were from a set of only 40 or 50, and so were all matched linearly quite early on in the column, thus greatly reducing the amount of calculation Excel needed to perform.

    For such a dataset, I cannot think of a feasible way in which you could obtain your results within a reasonable calculation time using worksheet formulas alone. I can only suggest that you re-post in the VBA section in the hope that such an approach will be of benefit.

    Regards

  32. #32
    Registered User
    Join Date
    12-17-2014
    Location
    London
    MS-Off Ver
    Excel 2007
    Posts
    12

    Re: Counting uniques

    @Xor

    Thank you very much for your time and help!

  33. #33
    Forum Expert XOR LX's Avatar
    Join Date
    04-18-2013
    Location
    Turin, Italy
    MS-Off Ver
    Office 365
    Posts
    7,742

    Re: Counting uniques

    Not at all. Like I said, apologies for having misinformed you, and hope you'll find a workaround of some sorts.

    Regards

+ Reply to Thread

Thread Information

Users Browsing this Thread

There are currently 1 users browsing this thread. (0 members and 1 guests)

Similar Threads

  1. Counting Uniques using 2 Criteria
    By dawiseman21 in forum Excel General
    Replies: 2
    Last Post: 10-03-2014, 04:21 PM
  2. Counting uniques based on several criteria
    By ricdik in forum Excel Formulas & Functions
    Replies: 4
    Last Post: 04-07-2014, 07:40 PM
  3. Counting uniques dates in a filtered column
    By d_brian in forum Excel Formulas & Functions
    Replies: 1
    Last Post: 10-24-2011, 01:35 PM
  4. Understanding How Counting Uniques Works
    By nothingisthis in forum Excel General
    Replies: 6
    Last Post: 04-02-2010, 01:58 PM
  5. [SOLVED] Counting Uniques - multiple criteria
    By Martin Just in forum Excel General
    Replies: 2
    Last Post: 01-12-2005, 07:06 PM

Tags for this Thread

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