+ Reply to Thread
Results 1 to 22 of 22

count comma separated information

  1. #1
    Registered User
    Join Date
    04-03-2010
    Location
    London, England
    MS-Off Ver
    Excel 2003
    Posts
    4

    count comma separated information

    Hi

    At the moment I'm trying to count comma separated information

    For example I Have in Cell A

    Cell A 1 - Server 1, Server 2 Server 3

    Cell A 2 - Server 1, Server 2

    What I want to basically is a formula to basically Say
    Server 1 = 2
    Server 2 = 2
    Server 3 =1

    I want it to show how many times its used if you get what I mean?

    Thanks

  2. #2
    Valued Forum Contributor tony h's Avatar
    Join Date
    03-14-2005
    Location
    England: London and Lincolnshire
    Posts
    1,187

    Re: count comma separated information

    you can split the comma seperated values into seperatecolumn using the "text to columns" function on the data tab

    then use countif to get the counts.


    click on the * Add Reputation if this was useful or entertaining.

  3. #3
    Forum Moderator - RIP Richard Buttrey's Avatar
    Join Date
    01-14-2008
    Location
    Stockton Heath, Cheshire, UK
    MS-Off Ver
    Office 365, Excel for Windows 2010 & Excel for Mac
    Posts
    29,464

    Re: count comma separated information

    Hi,

    Probably the easiest approach would be as follows,

    Use Data Text To columns to separate the strings into several columns.
    Copy each column underneath the first column to create a long list and then use Data Filter Advanced Filter to extract a unique list of Server references.

    Finally in a column adjacent to the unique list which starts in say E1, and where the long list is in column A, say cells A1:A100, in F1 enter

    =COUNTIF(A$1:A$100,E1)

    and copy this down the unique list rows.

    HTH
    Richard Buttrey

    RIP - d. 06/10/2022

    If any of the responses have helped then please consider rating them by clicking the small star icon below the post.

  4. #4
    Registered User
    Join Date
    04-03-2010
    Location
    London, England
    MS-Off Ver
    Excel 2003
    Posts
    4

    Re: count comma separated information

    Hi

    I can't use the Data Text to column because at the moment these are for each customers for example

    Customer one has Server 1,Server 2 and Server 3.

    If I move it to a different cell it will mess up it will go on the other cell

    I want to be able to read basically Cell A and say there are X Servers

    Is that possible ?

    Thank you


    Quote Originally Posted by Richard Buttrey View Post
    Hi,

    Probably the easiest approach would be as follows,

    Use Data Text To columns to separate the strings into several columns.
    Copy each column underneath the first column to create a long list and then use Data Filter Advanced Filter to extract a unique list of Server references.

    Finally in a column adjacent to the unique list which starts in say E1, and where the long list is in column A, say cells A1:A100, in F1 enter

    =COUNTIF(A$1:A$100,E1)

    and copy this down the unique list rows.

    HTH

  5. #5
    Forum Expert martindwilson's Avatar
    Join Date
    06-23-2007
    Location
    London,England
    MS-Off Ver
    office 97 ,2007
    Posts
    19,320

    Re: count comma separated information

    you arn't making it very clear why not! post a sample sheet.
    "Unless otherwise stated all my comments are directed at OP"

    Mojito connoisseur and now happily retired
    where does code go ?
    look here
    how to insert code

    how to enter array formula

    why use -- in sumproduct
    recommended reading
    wiki Mojito

    how to say no convincingly

    most important thing you need
    Martin Wilson: SPV
    and RSMBC

  6. #6
    Registered User
    Join Date
    04-03-2010
    Location
    London, England
    MS-Off Ver
    Excel 2003
    Posts
    4

    Re: count comma separated information

    Hi

    Attached is an example Excel Document

    Quote Originally Posted by martindwilson View Post
    you arn't making it very clear why not! post a sample sheet.
    Attached Files Attached Files

  7. #7
    Valued Forum Contributor tony h's Avatar
    Join Date
    03-14-2005
    Location
    England: London and Lincolnshire
    Posts
    1,187

    Re: count comma separated information

    That doesn't explain why you can't use text to columns

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

    Re: count comma separated information

    Based on the sample:

    E18:
    =SUMPRODUCT(--ISNUMBER(SEARCH(" "&REPLACE($D18,1,19,"")&","," "&$B$2:$B$5&",")))
    copied down

    Use of SUMPRODUCT is advised here as you may otherwise be open to false positives (ie normalise all terms per consistent delimiter), ie:

    =COUNTIF($B$2:$B$5,"*"&REPLACE($D18,1,19,"")&"*")

    would work for the sample but not if you changed one of the server 1 instances to say Server 11.

  9. #9
    Valued Forum Contributor tony h's Avatar
    Join Date
    03-14-2005
    Location
    England: London and Lincolnshire
    Posts
    1,187

    Re: count comma separated information

    =COUNTIFS(B2:B5,"=*" & C12& "*")

    where C12 is "Server 1"

    eg

    =COUNTIFS(B2:B5,"=*Server 1*")

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

    Re: count comma separated information

    Tony, the COUNTIF has already been illustrated (and highlighted as being susceptible to error) - not sure what this latest post is adding ?

    (also, use of equals operator not really required)

  11. #11
    Valued Forum Contributor tony h's Avatar
    Join Date
    03-14-2005
    Location
    England: London and Lincolnshire
    Posts
    1,187

    Re: count comma separated information

    Sorry

    Quote Originally Posted by DonkeyOte View Post
    Tony, the COUNTIF has already been illustrated (and highlighted as being susceptible to error) - not sure what this latest post is adding ?
    wise man say: when broadband down don't just post without checking for updates

    I get used to another forum where they warn you that there has been an intervening post before allowing you to commit your reply.

  12. #12
    Forum Expert martindwilson's Avatar
    Join Date
    06-23-2007
    Location
    London,England
    MS-Off Ver
    office 97 ,2007
    Posts
    19,320

    Re: count comma separated information

    could try
    =SUMPRODUCT(--(ISNUMBER(SEARCH("r 3,",TRIM($B$2:$B$5))))) note the space between r and 3
    Last edited by martindwilson; 04-04-2010 at 08:51 AM.

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

    Re: count comma separated information

    My point holds Martin that when dealing with delimited strings you should always normalise the strings by appending with delimiter (even if initially the terms appear mutually exclusive - this may not persist)

    Consider

    Server 1, Server 3, Server 4
    Server 1, Server 2, Server 3

    and we're looking for Server 3, using the last suggestion the result would be 1 rather than the correct value of 2 (the 2nd instance of Server 3 is not found given it is not followed by comma).

    To get the correct value we must append each string with the delimiter (ie add the comma to the end of each string so that the final term is consistent with those preceding it).

    If you opt not to normalise the strings there is no need to use SUMPRODUCT given a standard COUNTIF with wildcard would suffice, ie:

    =COUNTIF(B2:B5,"*r 3,*")

    would generate the same [albeit incorrect] result of 1


    The end result of all of the above is that I stand by my earlier suggestion of:

    =SUMPRODUCT(--ISNUMBER(SEARCH(" "&REPLACE($D18,1,19,"")&","," "&$B$2:$B$5&",")))

    In the above each string being searched (and criteria value) is appended such that first term is preceded by space and final term is followed by comma (ie all terms have consistent delimiter pattern)

  14. #14
    Forum Expert martindwilson's Avatar
    Join Date
    06-23-2007
    Location
    London,England
    MS-Off Ver
    office 97 ,2007
    Posts
    19,320

    Re: count comma separated information

    what about ?
    =SUMPRODUCT(--(ISNUMBER(SEARCH("r 3,",TRIM($B$2:$B$5&",")))))
    Last edited by martindwilson; 04-04-2010 at 09:01 AM.

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

    Re: count comma separated information

    Possibly, in terms of replacing your original.
    However, I see no value in reducing the term from "Server" to "r" given again this just adds to the possibility of false positives and by appending the strings that is what we're trying to avoid.

    This thread appears to have gone full circle - ie we're posting solutions that were posted half a dozen posts ago ...

  16. #16
    Forum Expert martindwilson's Avatar
    Join Date
    06-23-2007
    Location
    London,England
    MS-Off Ver
    office 97 ,2007
    Posts
    19,320

    Re: count comma separated information

    ok fair point on "server"
    =SUMPRODUCT(--ISNUMBER(SEARCH(" "&REPLACE($D18,1,19,"")&","," "&$B$2:$B$5&",")))
    =SUMPRODUCT(--(ISNUMBER(SEARCH("server 3,",TRIM($B$2:$B$5&",")))))
    look like different solutions to me.

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

    Re: count comma separated information

    Quote Originally Posted by mdw
    ...look like different solutions to me.
    Yes, the former is based on OP file and is designed such that it can be copied down without requiring alteration.
    (of course if the terms in D18 onwards reflected the terms being searched for the REPLACE could be dispensed with)

    Note also that the space acts as a delimiter also (front end) "server 3," is still open to false positives (theoretically at least)
    Last edited by DonkeyOte; 04-04-2010 at 09:16 AM. Reason: added note re: space delimiter

  18. #18
    Registered User
    Join Date
    04-03-2010
    Location
    London England
    MS-Off Ver
    Excel 2003
    Posts
    30

    Re: count comma separated information

    Joining this one late..

    if you just want to know the number of different values separated by commas you could just use..
    Please Login or Register  to view this content.
    where "D28" is the cell you want to count..

    I'm not sure what exactly you need.

  19. #19
    Forum Expert martindwilson's Avatar
    Join Date
    06-23-2007
    Location
    London,England
    MS-Off Ver
    office 97 ,2007
    Posts
    19,320

    Re: count comma separated information

    i had another look and still cant see why text to columns isn't doable,seeing as you can only have one instance of any server per customer(assumption )
    then when split over several columns and cleaned up just a simple
    =COUNTIF(B:D,"server 1")

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

    Re: count comma separated information

    @FunkyFox - though not related to the question I would suggest that rather than assume a default of +1 it is perhaps better to use a +(D28<>"")
    this would account for blank cells should the formula be applied to such (ie return 0 rather than 1).

    @mdw et al - the use of Text to Columns is based on some pretty fundamental assumptions.

    Given we're just reiterating posts already made I won't add further - so disregard my points as seen fit.
    Last edited by DonkeyOte; 04-04-2010 at 09:48 AM. Reason: typo

  21. #21
    Registered User
    Join Date
    04-03-2010
    Location
    London England
    MS-Off Ver
    Excel 2003
    Posts
    30

    Re: count comma separated information

    Well spotted DonkeyOte!

  22. #22
    Registered User
    Join Date
    04-03-2010
    Location
    London, England
    MS-Off Ver
    Excel 2003
    Posts
    4

    Thumbs up Re: count comma separated information

    Hi Everyone

    Thank You so much for the amazing help

    I have tried what martindwilson and donkeyote method and they both work

    Thank You again for the help

    Quote Originally Posted by martindwilson View Post
    ok fair point on "server"
    =SUMPRODUCT(--ISNUMBER(SEARCH(" "&REPLACE($D18,1,19,"")&","," "&$B$2:$B$5&",")))
    =SUMPRODUCT(--(ISNUMBER(SEARCH("server 3,",TRIM($B$2:$B$5&",")))))
    look like different solutions to me.

+ 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