Forum Discussion
Splitting multiple choice data into separate columns
Let's say Referrals is in B1 and the headings Acupuncture, Chiropractor etc. in C1, D1, ...
Enter the following formula in C2:
=IF(ISNUMBER(SEARCH(C$1,$B2)),"x","")
Fill to the right, then down (or vice versa).
See attached sample workbook.
- Riny_van_EekelenMay 14, 2022Platinum Contributor
Keith_Walworth Please find two possible PQ solutions in the attached workbook.
One is not dynamic, as it will split the referrals at every comma based on what it found when I created the script. And it hard-codes the new column names. If the number of items on any of the rows increases next time, the extra items will be ignored and you would have to manually adjust the script. But most of the script was created by just clicking in the user interface (except for the one step where you add an "X", which requires some typing). And it's not very complicated to fix the step that makes the split.
The second solution is dynamic. I finds out how many items are included in each row, finds the highest number and splits the column into the exact number of columns needed. But, it requires some manipulation of the underlying M-code.
- dofrancis3Sep 28, 2024Copper Contributor
Dear Riny_van_Eekelen
I reach out to you to request your support !
As per my Excel sheet attached, could you help me with a formula that can allow me to splitting multiple choice in multiple colomns.
I can get result only for one colomn but i would like to get results for 2 or 3 colomns.
Thank you for your support.
- SergeiBaklanSep 28, 2024Diamond Contributor
That will be much better if you start new discussion with that question rather than continue quite old thread.
In brief, you may use =ISNUMBER(SEARCH(...)) + ISNUMBER)SEARCH(...))
- SergeiBaklanMay 14, 2022Diamond Contributor
Riny_van_Eekelen , Keith_Walworth
One more variant, bit more coding
Script is
let Source = Excel.CurrentWorkbook(){[Name="Table1"]}[Content], TextToList = Table.AddColumn( Source, "Custom", each List.Transform(Text.Split([Referrals], ","), Text.Trim) ), a = List.Sort( List.Distinct( List.Combine( TextToList[Custom]) ) ), IfContains = Table.AddColumn(TextToList, "Flags", each [ b =[Custom], c=List.Transform(a, each if List.Contains(b, _) then "x" else "" ) ][c] ), toTable = Table.FromColumns( List.Zip( IfContains[Flags] ), a) in toTable
- HansVogelaarMay 13, 2022MVP
I'll leave that for someone who knows PowerQuery.