+ Reply to Thread
Results 1 to 20 of 20

Get a count of a combination of 2 different columns values, (not a sum, Just a count)

  1. #1
    Registered User
    Join Date
    12-28-2020
    Location
    London, England
    MS-Off Ver
    2016
    Posts
    9

    Post Get a count of a combination of 2 different columns values, (not a sum, Just a count)

    I need vba code or formula which can does the following, i am not a excel programmer, I am a C# developer, in one of the project I need to process some data from excel, which has 2 million rows! please some expert can help me, here is my problem, I have to insert count of each combination value from column 1 and column 2, what is the best way?
    Column 1 Column 2 Count
    20 1
    20 1
    20 1 3
    20 2
    20 2
    20 2 3
    20 3 1
    22 1
    22 1
    22 1 3
    22 2
    22 2 2
    Attached Files Attached Files
    Last edited by Jayakumar_vba; 12-28-2020 at 08:16 AM. Reason: uploaded sample file

  2. #2
    Forum Moderator AliGW's Avatar
    Join Date
    08-10-2013
    Location
    Retired in Ipswich, Suffolk, but grew up in Sawley, Derbyshire (England)
    MS-Off Ver
    MS 365 Subscription Insider Beta Channel v. 2404 (Windows 11 22H2 64-bit)
    Posts
    80,420

    Re: Get a count of a combination of 2 different columns values, (not a sum, Just a count)

    The maximum rows an Excel workbook can have is 1,048,576.

    You could use COUNTIFS for this.

    There are instructions at the top of the page explaining how to attach your sample workbook.
    Ali


    Enthusiastic self-taught user of MS Excel who's always learning!
    Don't forget to say "thank you" in your thread to anyone who has offered you help.
    You can reward them by clicking on * Add Reputation below their user name on the left, if you wish.

    Forum Rules (updated August 2023): please read them here.

  3. #3
    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
    43,984

    Re: Get a count of a combination of 2 different columns values, (not a sum, Just a count)

    One way... whether the quickest or not is another matter!!

    =IF(COUNTIFS($A$2:A2,A2,$B$2:B2,B2)=COUNTIFS(A:A,A2,B:B,B2),COUNTIFS(A:A,A2,B:B,B2),"")
    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

  4. #4
    Registered User
    Join Date
    12-28-2020
    Location
    London, England
    MS-Off Ver
    2016
    Posts
    9

    Re: Get a count of a combination of 2 different columns values, (not a sum, Just a count)

    I am not allowed to post any links 'You are not allowed to post any kinds of links, images or videos until you post a few times.'

  5. #5
    Registered User
    Join Date
    12-28-2020
    Location
    London, England
    MS-Off Ver
    2016
    Posts
    9

    Re: Get a count of a combination of 2 different columns values, (not a sum, Just a count)

    Hi Glenn, Thanks for your solution, but it didn't work for me.

  6. #6
    Forum Moderator AliGW's Avatar
    Join Date
    08-10-2013
    Location
    Retired in Ipswich, Suffolk, but grew up in Sawley, Derbyshire (England)
    MS-Off Ver
    MS 365 Subscription Insider Beta Channel v. 2404 (Windows 11 22H2 64-bit)
    Posts
    80,420

    Re: Get a count of a combination of 2 different columns values, (not a sum, Just a count)

    You were not asked for a link - read the yellow banner, as instructed.

    "Didn't work" tells us nothing of any use - can you be more specific?

  7. #7
    Registered User
    Join Date
    12-28-2020
    Location
    London, England
    MS-Off Ver
    2016
    Posts
    9

    Re: Get a count of a combination of 2 different columns values, (not a sum, Just a count)

    Quote Originally Posted by AliGW View Post
    The maximum rows an Excel workbook can have is 1,048,576.

    You could use COUNTIFS for this.

    There are instructions at the top of the page explaining how to attach your sample workbook.
    Hi AliGW, Thank you for you solution, just countifs is not enough, I have tried already, also another user Glenn Kennedy provided the solution, but even that didn't work.

  8. #8
    Forum Moderator AliGW's Avatar
    Join Date
    08-10-2013
    Location
    Retired in Ipswich, Suffolk, but grew up in Sawley, Derbyshire (England)
    MS-Off Ver
    MS 365 Subscription Insider Beta Channel v. 2404 (Windows 11 22H2 64-bit)
    Posts
    80,420

    Re: Get a count of a combination of 2 different columns values, (not a sum, Just a count)

    Please read post #6.

    COUNTIFS will work if you use it properly as Glenn showed you, unless your real data is not what you've shown us.

  9. #9
    Registered User
    Join Date
    12-28-2020
    Location
    London, England
    MS-Off Ver
    2016
    Posts
    9

    Re: Get a count of a combination of 2 different columns values, (not a sum, Just a count)

    Well, I need to get count of combination of two columns, but countifs is giving a value of one row. I can see my sample file is attached to a thread now.

  10. #10
    Forum Moderator AliGW's Avatar
    Join Date
    08-10-2013
    Location
    Retired in Ipswich, Suffolk, but grew up in Sawley, Derbyshire (England)
    MS-Off Ver
    MS 365 Subscription Insider Beta Channel v. 2404 (Windows 11 22H2 64-bit)
    Posts
    80,420

    Re: Get a count of a combination of 2 different columns values, (not a sum, Just a count)

    Please read and act on post #6!!!!

  11. #11
    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
    43,984

    Re: Get a count of a combination of 2 different columns values, (not a sum, Just a count)

    Well, it worked for me. I cannot tell what you did wrong, though!!
    Attached Files Attached Files

  12. #12
    Forum Moderator AliGW's Avatar
    Join Date
    08-10-2013
    Location
    Retired in Ipswich, Suffolk, but grew up in Sawley, Derbyshire (England)
    MS-Off Ver
    MS 365 Subscription Insider Beta Channel v. 2404 (Windows 11 22H2 64-bit)
    Posts
    80,420

    Re: Get a count of a combination of 2 different columns values, (not a sum, Just a count)

    All you had to do was change the start of the ranges like this:

    =IF(COUNTIFS($A$1:A1,A1,$B$1:B1,B1)=COUNTIFS(A:A,A1,B:B,B1),COUNTIFS(A:A,A1,B:B,B1),"")

    This WORKS in your attached sample.

  13. #13
    Registered User
    Join Date
    12-28-2020
    Location
    London, England
    MS-Off Ver
    2016
    Posts
    9

    Re: Get a count of a combination of 2 different columns values, (not a sum, Just a count)

    Quote Originally Posted by Glenn Kennedy View Post
    Well, it worked for me. I cannot tell what you did wrong, though!!
    Hi Glen, It is worked ! my first row was blank, Sorry for my bad. Thank you very much for your help, very much appreciated.

  14. #14
    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
    43,984

    Re: Get a count of a combination of 2 different columns values, (not a sum, Just a count)

    You're welcome.



    If that takes care of your original question, please select "Thread Tools" from the menu link above and mark this thread as SOLVED.

    It would also be very nice if you were to just click the Add Reputation button at the foot of any of the posts of members who helped you reach a solution.

  15. #15
    Registered User
    Join Date
    12-28-2020
    Location
    London, England
    MS-Off Ver
    2016
    Posts
    9

    Re: Get a count of a combination of 2 different columns values, (not a sum, Just a count)

    Quote Originally Posted by AliGW View Post
    All you had to do was change the start of the ranges like this:

    =IF(COUNTIFS($A$1:A1,A1,$B$1:B1,B1)=COUNTIFS(A:A,A1,B:B,B1),COUNTIFS(A:A,A1,B:B,B1),"")

    This WORKS in your attached sample.
    Yes, it worked, Sorry my bad, my first row was blank. Thank you for your help, very much appreciated.

  16. #16
    Forum Moderator AliGW's Avatar
    Join Date
    08-10-2013
    Location
    Retired in Ipswich, Suffolk, but grew up in Sawley, Derbyshire (England)
    MS-Off Ver
    MS 365 Subscription Insider Beta Channel v. 2404 (Windows 11 22H2 64-bit)
    Posts
    80,420

    Re: Get a count of a combination of 2 different columns values, (not a sum, Just a count)

    If that takes care of your original question, please select Thread Tools from the menu link above and mark this thread as SOLVED.

    Also, you may not be aware that you can thank those who have helped you by clicking the small star icon located in the lower left corner of the post in which the help was given. By doing so you can add to the reputation(s) of those who helped.

  17. #17
    Registered User
    Join Date
    12-28-2020
    Location
    London, England
    MS-Off Ver
    2016
    Posts
    9

    Re: Get a count of a combination of 2 different columns values, (not a sum, Just a count)

    Glen, how do i make answer as Solved?
    Last edited by AliGW; 12-28-2020 at 08:48 AM. Reason: PLEASE don't quote unnecessarily!

  18. #18
    Forum Moderator AliGW's Avatar
    Join Date
    08-10-2013
    Location
    Retired in Ipswich, Suffolk, but grew up in Sawley, Derbyshire (England)
    MS-Off Ver
    MS 365 Subscription Insider Beta Channel v. 2404 (Windows 11 22H2 64-bit)
    Posts
    80,420

    Re: Get a count of a combination of 2 different columns values, (not a sum, Just a count)

    Glenn and I have both already told you how:

    If that takes care of your original question, please select Thread Tools from the menu link above and mark this thread as SOLVED.

  19. #19
    Registered User
    Join Date
    12-28-2020
    Location
    London, England
    MS-Off Ver
    2016
    Posts
    9

    Re: Get a count of a combination of 2 different columns values, (not a sum, Just a count)

    Glenn & AliGW, done, Thank you.

  20. #20
    Forum Moderator AliGW's Avatar
    Join Date
    08-10-2013
    Location
    Retired in Ipswich, Suffolk, but grew up in Sawley, Derbyshire (England)
    MS-Off Ver
    MS 365 Subscription Insider Beta Channel v. 2404 (Windows 11 22H2 64-bit)
    Posts
    80,420

    Re: Get a count of a combination of 2 different columns values, (not a sum, Just a count)

    Glad we got there.

+ 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] Count duplicate text values in columns whilst ignoring/excluding certain values
    By adamwestwell in forum Excel Formulas & Functions
    Replies: 4
    Last Post: 06-02-2017, 05:34 AM
  2. (Count Formula) Count if two seperate ranges create unique combination
    By Geekcrux in forum Excel Formulas & Functions
    Replies: 2
    Last Post: 01-10-2016, 07:00 AM
  3. Replies: 5
    Last Post: 08-16-2015, 09:55 PM
  4. [SOLVED] Sort and Count Unique List Across Multiple Columns - Student Count
    By BuntyMac in forum Excel Formulas & Functions
    Replies: 22
    Last Post: 08-17-2014, 07:00 AM
  5. Replies: 2
    Last Post: 01-21-2014, 02:53 PM
  6. count of combination of some values
    By yasar in forum Excel Programming / VBA / Macros
    Replies: 3
    Last Post: 05-20-2013, 04:36 AM
  7. Range.columns.count property returns wrong count after union operation
    By gopinan in forum Excel Programming / VBA / Macros
    Replies: 2
    Last Post: 10-13-2008, 04:48 AM

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