+ Reply to Thread
Results 1 to 14 of 14

Convert/count comma separated values into columns with boolean values

  1. #1
    Registered User
    Join Date
    05-23-2023
    Location
    Rotterdam, Netherlands
    MS-Off Ver
    16.73
    Posts
    6

    Convert/count comma separated values into columns with boolean values

    Hi all,

    I am trying to save the following problem: a surveyor has supplied me with a dataset that contains a column representing the return of a set of checkboxes in a survey. So, for example, in an option-set containing 11 options, the checkboxes are numbered 1 to 11. For every checked box its value is added to a single cell, comma separated (e.g. 1,5,6,9,10). My challenge is to extract the values from the commas separated list, using a formula and convert them into boolean values. So, with 11 options in my example, it would result in 11 columns containing boolean values (1=checked, 0 unchecked). I explored using IF, COUNTIF/COUNTIFS and SUBSTITUTE but I run into a few problems:
    - only checked options return a result, so I can't use the positions as a means to identify the values;
    - not all cells have multiple values, so there is not always a comma;
    - adding wildcards doesn't seem to work. I end up with false positives for column 1, as values 10 and 11 are also identified;
    - I would like a future proof solution, as I cannot be certain that the checkbox results are ordered (ascending/descending).

    I have made an example worksheet to illustrate the problem. I am sorry if this would seem basic stuff to some of you, but I am stuck. Many thanks in advance for giving it your thought and attention.


    Jan-Willem
    Attached Files Attached Files
    Last edited by Jannem; 05-25-2023 at 04:44 AM.
    Jan-Willem
    Datamanagement/research

  2. #2
    Forum Guru
    Join Date
    03-02-2006
    Location
    Los Angeles, Ca
    MS-Off Ver
    Win10/MSO2016
    Posts
    12,994

    Re: Convert/count comma separated values into columns with boolean values

    B2:
    Please Login or Register  to view this content.
    edit: I just noticed that it doesn't work with 1 vs 11, I'll look at it later...
    Attached Files Attached Files
    Last edited by protonLeah; 05-24-2023 at 06:55 PM.
    Ben Van Johnson

  3. #3
    Forum Guru TMS's Avatar
    Join Date
    07-15-2010
    Location
    The Great City of Manchester, NW England ;-)
    MS-Off Ver
    MSO 2007,2010,365
    Posts
    48,943

    Re: Convert/count comma separated values into columns with boolean values

    This works but NOT output to a Structured Table. Some of your expected results are wrong, and you have some full stops instead of commas.

    Formula: copy to clipboard
    Please Login or Register  to view this content.
    copied down.

    Cancel that assertion. Same problem with 1 and 11
    Last edited by TMS; 05-24-2023 at 07:03 PM.
    Trevor Shuttleworth - Retired Excel/VBA Consultant

    I dream of a better world where chickens can cross the road without having their motives questioned

    'Being unapologetic means never having to say you're sorry' John Cooper Clarke


  4. #4
    Forum Guru TMS's Avatar
    Join Date
    07-15-2010
    Location
    The Great City of Manchester, NW England ;-)
    MS-Off Ver
    MSO 2007,2010,365
    Posts
    48,943

    Re: Convert/count comma separated values into columns with boolean values

    Ok, this copes with 1 and 11.

    Formula: copy to clipboard
    Please Login or Register  to view this content.

  5. #5
    Registered User
    Join Date
    05-23-2023
    Location
    Rotterdam, Netherlands
    MS-Off Ver
    16.73
    Posts
    6

    Re: Convert/count comma separated values into columns with boolean values

    Hi TMS,

    Many thanks for your advice and effort. I had to alter the formulas slightly, as my version of Excel separates the arguments within the function with semicolons instead of comma's.

    Formula: copy to clipboard
    Please Login or Register  to view this content.


    Also had to manage the fact that the formula 'spills' over to next columns (didn't anticipate that). So, converted table back to a range, made room for the function to spill over. Now it all works perfectly, also in the actual worksheet. So many thanks again!
    Last edited by Jannem; 05-25-2023 at 02:36 AM.

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

    Re: Convert/count comma separated values into columns with boolean values

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

    Also, if you have not already done so, you may not be aware that you can thank anyone who offered you help towards a solution for your issue by clicking the small star icon (* Add Reputation) 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 all those who offered help.
    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. It's a universal courtesy.
    You can reward them by clicking on * Add Reputation below their user name on the left, if you wish.

    NB:
    as a Moderator, I never accept friendship requests.
    Forum Rules (updated August 2023): please read them here.

  7. #7
    Registered User
    Join Date
    05-23-2023
    Location
    Rotterdam, Netherlands
    MS-Off Ver
    16.73
    Posts
    6

    Re: Convert/count comma separated values into columns with boolean values

    Hi Trevor,

    Your solution is perfectly usable in a standard range, but it doesn't seem to work in a table.

    Excel-help confirms this: "Spilled array formulas aren't supported in Excel tables. Try moving your formula out of the table, or converting the table to a range."

    I would prefer your fully automated/dynamic formula, but as this doesn't work in a table. Do you have any pointers how the formula would look like if it was coded per column (representing the 'checkbox'-ID). Thanks again for your consideration!

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

    Re: Convert/count comma separated values into columns with boolean values

    Try this:

    =IFERROR(IF(FIND(" "&Table3[[#Headers],[1]]&" ",SUBSTITUTE(SUBSTITUTE(" "&[@Source]&" ",","," "),"."," ")),1),0)

    =ALS.FOUT(ALS(VIND.ALLES(" "&Table3[[#Kopteksten];[1]]&" ";SUBSTITUEREN(SUBSTITUEREN(" "&[@Source]&" ";",";" ");".";" "));1);0)

  9. #9
    Forum Moderator AliGW's Avatar
    Join Date
    08-10-2013
    Location
    Retired in Ipswich, Suffolk, but grew up in Sawley, Derbyshire (both in England)
    MS-Off Ver
    MS 365 Subscription Insider Beta Channel v. 2507 (Windows 11 Home 24H2 64-bit)
    Posts
    91,792

    Re: Convert/count comma separated values into columns with boolean values

    Correction. This copied across and down:

    =IFERROR(IF(FIND(" "&Table3[[#Headers],[1]]&" ",SUBSTITUTE(SUBSTITUTE(" "&Table3[@[Source]:[Source]]&" ",","," "),"."," ")),1),0)

    =ALS.FOUT(ALS(VIND.ALLES(" "&Table3[[#Kopteksten];[1]]&" ";SUBSTITUEREN(SUBSTITUEREN(" "&Table3[@[Source]:[Source]]&" ";",";" ");".";" "));1);0)
    Attached Files Attached Files

  10. #10
    Forum Guru TMS's Avatar
    Join Date
    07-15-2010
    Location
    The Great City of Manchester, NW England ;-)
    MS-Off Ver
    MSO 2007,2010,365
    Posts
    48,943

    Re: Convert/count comma separated values into columns with boolean values

    You're welcome. Thanks for the rep.

    Your solution is perfectly usable in a standard range, but it doesn't seem to work in a table.
    I did say this in my first post
    This works but NOT output to a Structured Table.
    But Ali's solution works well.

  11. #11
    Forum Expert shukla.ankur281190's Avatar
    Join Date
    05-17-2014
    Location
    Lucknow, India
    MS-Off Ver
    Microsoft® Excel® for Microsoft 365 MSO (Version 2503 Build 16.0.18604.20000) 64-bit
    Posts
    4,000

    Re: Convert/count comma separated values into columns with boolean values

    Try

    B2
    Formula: copy to clipboard
    Please Login or Register  to view this content.
    If I helped, Don't forget to add reputation (click on the little star ★ at bottom of this post)
    Don't forget to mark threads as "Solved" (Thread Tools->Mark thread as Solved)

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

    Re: Convert/count comma separated values into columns with boolean values

    Thanks for the rep. Glad to have helped.

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

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

    Re: Convert/count comma separated values into columns with boolean values

    IN B2 copied to full range
    Formula: copy to clipboard
    Please Login or Register  to view this content.
    Attached Files Attached Files
    Pl note
    Array formula should be confirmed with Ctrl+Shift+Enter keys together.
    If answere is satisfactory press * to add reputation.

  14. #14
    Registered User
    Join Date
    05-23-2023
    Location
    Rotterdam, Netherlands
    MS-Off Ver
    16.73
    Posts
    6

    Re: Convert/count comma separated values into columns with boolean values

    Quote Originally Posted by kvsrinivasamurthy View Post
    IN B2 copied to full range
    Formula: copy to clipboard
    Please Login or Register  to view this content.
    Thanks. This works too, however the solution by AliGW is better for me, as it is more tolerant of different formatting of the source cells (either using periods, comma's or spaces as a delimiter).

+ 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 set of comma separated values within another paired columns
    By Gulya in forum Excel Formulas & Functions
    Replies: 9
    Last Post: 02-06-2023, 04:05 AM
  2. Convert comma-separated values into columns
    By educamboi in forum Excel Programming / VBA / Macros
    Replies: 4
    Last Post: 04-12-2021, 07:43 AM
  3. Replies: 4
    Last Post: 12-01-2020, 01:20 PM
  4. How to count values separated by a comma
    By peterderrington in forum Excel Formulas & Functions
    Replies: 6
    Last Post: 03-24-2017, 11:50 AM
  5. [SOLVED] Macro to give the count of unique values after comparing the comma separated values
    By Manish_Gupta in forum Excel Programming / VBA / Macros
    Replies: 3
    Last Post: 03-03-2014, 12:41 AM
  6. [SOLVED] How to count values separated by a comma
    By PlamSa in forum Excel Formulas & Functions
    Replies: 15
    Last Post: 11-19-2013, 09:10 AM
  7. count of comma separated values
    By bujji1305 in forum Excel Programming / VBA / Macros
    Replies: 8
    Last Post: 06-01-2012, 07:33 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