+ Reply to Thread
Results 1 to 12 of 12

Count The Order Of Occurrence Of Duplicates In Excel/formula to return only unique value

  1. #1
    Forum Contributor
    Join Date
    02-06-2013
    Location
    Maryland
    MS-Off Ver
    Excel 2010
    Posts
    1,000

    Count The Order Of Occurrence Of Duplicates In Excel/formula to return only unique value

    Looking for non-array formula to return unique value in Excel. COUNTIF($A$2:$A2,A2) works fine but it is crashing the excel workbook due to the dataset volume (over 200,000 rows). If there is a non-array formula that uses less computing memory, will appreciate it.

    See attached sample file.

    Thanks
    Attached Files Attached Files

  2. #2
    Forum Expert BMV's Avatar
    Join Date
    01-13-2020
    Location
    St-Petersburg, Russia
    MS-Off Ver
    2013-2016
    Posts
    1,329

    Re: Count The Order Of Occurrence Of Duplicates In Excel/formula to return only unique val

    This data for MsQuery, PowerQuery, PivotTable or VBA but not for formula . Even Advanced filter can be used.

  3. #3
    Forum Contributor
    Join Date
    02-06-2013
    Location
    Maryland
    MS-Off Ver
    Excel 2010
    Posts
    1,000

    Re: Count The Order Of Occurrence Of Duplicates In Excel/formula to return only unique val

    BMV: goal is to use a formula. If you are able to, please go ahead.

    Thanks

  4. #4
    Forum Moderator
    Join Date
    01-21-2014
    Location
    St. Joseph, Illinois U.S.A.
    MS-Off Ver
    Office 365 v 2403
    Posts
    13,406

    Re: Count The Order Of Occurrence Of Duplicates In Excel/formula to return only unique val

    Try in cell B2 and fill down.
    Formula: copy to clipboard
    Please Login or Register  to view this content.
    Dave

  5. #5
    Forum Moderator
    Join Date
    01-21-2014
    Location
    St. Joseph, Illinois U.S.A.
    MS-Off Ver
    Office 365 v 2403
    Posts
    13,406

    Re: Count The Order Of Occurrence Of Duplicates In Excel/formula to return only unique val

    Or insert a helper column using the 'Fill Series' feature. I inserted a new column A in the attached. It cuts way down on calculation overhead. Also to avoid unnecessary overhead of IFERROR array enter this single helper cell in F1 to count the number of unique values.
    Formula: copy to clipboard
    Please Login or Register  to view this content.


    Enter this formula in E2 and fill down.
    Formula: copy to clipboard
    Please Login or Register  to view this content.

  6. #6
    Forum Expert
    Join Date
    07-06-2004
    Location
    Northern California
    MS-Off Ver
    2K, 2003, 2010, O365
    Posts
    1,490

    Re: Count The Order Of Occurrence Of Duplicates In Excel/formula to return only unique val

    Your sample workbook may be too simplistic. Presumably you have a single column range spanning over 200,000 rows, but your example shows column A sorted in ascending order. If that's the case, a 2 cell/result approach would be most efficient. Data assumed in Other!$A$3:$A$205000, first distinct value in active worksheet cell AA5.

    AA5: =Other!$A$3

    AB5: =COUNTIF(Other!$A$3:$A$205000,AA5)+1

    AA6: =INDEX(Other!$A$3:$A$205000,AA5)

    AA6: =COUNTIF(INDEX(Other!$A$3:$A$205000,AB5):Other!$A$205000,AA6)+AB5

    Select AA6:AB6 and fill down as far as needed. Note that the column AB formulas perform COUNTIF on successively smaller ranges in lower rows.


    If your data isn't sorted, it should be with that many records. Also, you could really boost performance by adding supporting formulas in the Other worksheet.

    X3: =A3<>A4

    Fill X3 down into X4:X205000.

    Y3: =MATCH(TRUE,X3:X$205000,0)

    Y4: =IF(X3,MATCH(TRUE,X4:X$205000,0))

    Fill Y4 down into Y5:Y205000.

    Z2: =COUNT(Z3:Z205000)

    Z3: =Y3

    Z4: =Z3+INDEX(Y$3:Y$205000,Z3+1)

    Fill Z4 down until it produces #REF! errors. The col Z values are row indices of the last/bottommost instances of each distinct value in Other!A3:A205000.

    Generate a list of distinct values from Other!A3:A205000 as

    AA3: =IF(ROWS(AA$3:AA3)<=Other!$Z$2,INDEX(Other!$A$3:$A$205000,INDEX(Other!$Z$3:$Z$205000,ROWS(AA$3:AA3))),#NULL!)

    Fill AA3 down until it produces #NULL! errors. FWIW, I believe this is the most efficient way to index distinct values until Excel provides the UNIQUE function to all. The first approach above is O(N^2) while the second approach is O(N log(N)) because MATCH is more efficient than COUNTIF. COUNTIF processes it's entire 1st argument range, while MATCH stops once it finds a match.
    Last edited by hrlngrv; 01-14-2020 at 01:12 AM. Reason: typos

  7. #7
    Forum Expert BMV's Avatar
    Join Date
    01-13-2020
    Location
    St-Petersburg, Russia
    MS-Off Ver
    2013-2016
    Posts
    1,329

    Re: Count The Order Of Occurrence Of Duplicates In Excel/formula to return only unique val

    Quote Originally Posted by bjnockle View Post
    BMV: goal is to use a formula. If you are able to, please go ahead.

    Thanks
    Any formulas will work slow for 200k rows. I have 2 versions of Excel and x32 can't fill down any of offered and created by my self at all
    =IF(MATCH(A2;$A$1:A2;)=ROW();ROW())
    and
    =IFERROR(INDEX(A:A;SMALL($C$2:$C$200000;ROW(D1)));"")

  8. #8
    Forum Contributor
    Join Date
    02-06-2013
    Location
    Maryland
    MS-Off Ver
    Excel 2010
    Posts
    1,000

    Re: Count The Order Of Occurrence Of Duplicates In Excel/formula to return only unique val

    FlameRetired: Is there a way to use helper column and bypass "Countif" to return the first occurrence of a value in a column? This
    Please Login or Register  to view this content.
    formula is crashing the excel workbook because it has over 290,000 rows. If there is helper column and the formula is not forcing Excel to execute the "calculating operation, which slows down the sheet considerably and/or crashes it. See example workbook from initial post.

    Thanks

  9. #9
    Forum Contributor
    Join Date
    02-06-2013
    Location
    Maryland
    MS-Off Ver
    Excel 2010
    Posts
    1,000

    Re: Count The Order Of Occurrence Of Duplicates In Excel/formula to return only unique val

    BMV: Is there a way to use helper column and bypass "=IF(MATCH(A2;$A$1:A2=ROW();ROW())" to return the first occurrence of a value in a column? This
    Please Login or Register  to view this content.
    formula is crashing the excel workbook because it has over 290,000 rows. If there is helper column and the formula is not forcing Excel to execute the "calculating operation, which slows down the sheet considerably and/or crashes it. See example workbook from initial post.

    Thanks

  10. #10
    Forum Expert BMV's Avatar
    Join Date
    01-13-2020
    Location
    St-Petersburg, Russia
    MS-Off Ver
    2013-2016
    Posts
    1,329

    Re: Count The Order Of Occurrence Of Duplicates In Excel/formula to return only unique val

    bjnockle,I think you should return to #2. Why not PivotTable or MsQuery. Last one need path correction and it can be done by small macro or manually. And look at the #6. Sorted data can be calculated very easy.

  11. #11
    Forum Contributor
    Join Date
    02-06-2013
    Location
    Maryland
    MS-Off Ver
    Excel 2010
    Posts
    1,000

    Re: Count The Order Of Occurrence Of Duplicates In Excel/formula to return only unique val

    BMV: And look at the #6. Could not follow #6. I think there is a way to use multiple helper columns to achieve the same result.

    Thanks

  12. #12
    Forum Expert
    Join Date
    07-20-2011
    Location
    Mysore, India.
    MS-Off Ver
    Excel 2019
    Posts
    8,587

    Re: Count The Order Of Occurrence Of Duplicates In Excel/formula to return only unique val

    Is the data is sorted in original file as shown in sample file. if it is so in c2 then copy down

    =IF(A2=A1,C1+1,1)
    Attached Files Attached Files
    Last edited by kvsrinivasamurthy; 01-30-2020 at 04:39 AM.
    Pl note
    Array formula should be confirmed with Ctrl+Shift+Enter keys together.
    If answere is satisfactory press * to add reputation.

+ 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. [SOLVED] How to count the order of occurrence of duplicates
    By orehovka in forum Excel Formulas & Functions
    Replies: 10
    Last Post: 06-28-2023, 11:29 PM
  2. Sumproduct formula to ignore duplicates or return unique values only
    By Xsample in forum Excel Formulas & Functions
    Replies: 11
    Last Post: 07-08-2022, 11:09 AM
  3. [SOLVED] count unique occurrence by id
    By ZedaG in forum Excel Formulas & Functions
    Replies: 4
    Last Post: 08-04-2019, 08:36 AM
  4. Count Function Occurrence No Duplicates
    By excelCEC1234 in forum Excel Formulas & Functions
    Replies: 1
    Last Post: 05-09-2019, 10:29 AM
  5. Count occurrence per row ignoring duplicates in column
    By braun.reivn in forum Excel Formulas & Functions
    Replies: 6
    Last Post: 05-24-2015, 09:53 PM
  6. [SOLVED] Formula to count duplicates in 1, 2, 3 order
    By kas05j in forum Excel Formulas & Functions
    Replies: 3
    Last Post: 08-25-2014, 11:02 AM
  7. Replies: 10
    Last Post: 06-13-2013, 04:12 PM

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