+ Reply to Thread
Results 1 to 7 of 7

Count distinct values based on criteria (large data)

  1. #1
    Registered User
    Join Date
    09-16-2018
    Location
    macau
    MS-Off Ver
    ms office 2018 for mac
    Posts
    17

    Count distinct values based on criteria (large data)

    Hi all,

    i am counting distinct value (no of invoices) by 3 criteria (year, month and date). i looked up different tutorials and find most of them suggested to use sum(if(1/countifs). I tried and tested the formula and it worked if the data was small, such as 50 rows. However, when i returned to the reality, for over 50,000 and more rows, it took quite a few minute to load the formula and it always showed "0". Can someone please help to find out which mistake I made and tell any solutions?

    *the file is too large, over 1000md that I have to cut out some of the cells...before i upload.

    Thank you.
    Attached Files Attached Files

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

    Re: Count distinct values based on criteria (large data)

    Hi,

    It's unfortunate that the reciprocal COUNTIF(S) construction for counting unique values is so widely touted across the various Excel help sites/forums, since it is vastly inefficient.

    Far better is the FREQUENCY/MATCH set-up, i.e., array formula**:

    =SUM(IF(FREQUENCY(IF(Brio[Sales Year]=$G$1,IF(Brio[Sales Month]=$G$2,IF(Brio[Sales Date]<=G3,MATCH(Brio[Invoice No],Brio[Invoice No],0)))),ROW(Brio[Invoice No])-MIN(ROW(Brio[Invoice No]))+1),1))

    Also, I notice that you were referencing entire columns within your formula, which is not at all a good idea: array formulas calculate over all cells passed to them, whether technically beyond the last-used cells in those ranges or not.

    Besides, you appear to be using a Structured Table here, which will automatically expand/contract as new rows are added/deleted, so simply by using Structured References within your formula, as I have done above, you avoid the need to manually set the upper row reference.

    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/

  3. #3
    Registered User
    Join Date
    09-16-2018
    Location
    macau
    MS-Off Ver
    ms office 2018 for mac
    Posts
    17

    Re: Count distinct values based on criteria (large data)

    thank you for your prompt reply and solution first.

    As you mentioned and suggested, not to reference all columns. however, as the data will be updated date by date, more cells will be filled. How should the formula handle?

  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: Count distinct values based on criteria (large data)

    Did you read the part about Structured References/Tables in my previous post?

    Regards

  5. #5
    Forum Expert
    Join Date
    09-25-2015
    Location
    Milan Italy
    MS-Off Ver
    office 365
    Posts
    1,781

    Re: Count distinct values based on criteria (large data)

    Pivot table with data model for distinct count

    http://www.filedropper.com/countdist...tabledatamodel


    Tutorial

    https://www.youtube.com/watch?v=sId8vpdp1qw



    Saluti XOR LX
    Last edited by CARACALLA; 04-02-2020 at 05:27 AM.

  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: Count distinct values based on criteria (large data)

    Buona alternativa, CARACALLA. Inoltre, sarą pił efficiente.

    Spero che stia bene li a Milano. Tempi difficili qui al nord...

    Saluti,

  7. #7
    Forum Expert
    Join Date
    09-25-2015
    Location
    Milan Italy
    MS-Off Ver
    office 365
    Posts
    1,781

    Re: Count distinct values based on criteria (large data)

    Tutto bene .Spero lo stesso per te

    Saluti

+ 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. Count Distinct Values With A Criteria In A Filtered List
    By JonnyBoy333 in forum Excel Formulas & Functions
    Replies: 1
    Last Post: 08-31-2019, 02:52 AM
  2. [SOLVED] Count of Distinct function/ Formula based on multiple criteria
    By naveeddil in forum Excel Formulas & Functions
    Replies: 4
    Last Post: 05-08-2019, 06:34 PM
  3. [SOLVED] Count of distinct values between two date ranges
    By HKPHOOY in forum Excel Formulas & Functions
    Replies: 26
    Last Post: 03-01-2018, 02:39 PM
  4. Sum column and count distinct values in another based on multiple criteria
    By mike.greene in forum Excel Formulas & Functions
    Replies: 12
    Last Post: 01-12-2015, 11:50 AM
  5. Count distinct values that correspond to a criteria
    By Eduard in forum Excel Programming / VBA / Macros
    Replies: 23
    Last Post: 04-22-2013, 01:03 PM
  6. Distinct count based on multiple criteria - am I on the right track?
    By thedunnyman in forum Excel Formulas & Functions
    Replies: 3
    Last Post: 03-26-2012, 07:36 AM
  7. Count distinct values with criteria
    By greencardioid in forum Excel Formulas & Functions
    Replies: 6
    Last Post: 07-29-2008, 06:48 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