Create a Line by Line Comma Separated String from Data Table

Simonc64

Active Member
Joined
Feb 15, 2007
Messages
251
Office Version
  1. 365
This is my sample datasheet.......
ABCDEFG
1100200300400500Result
2Customer AYesYesNoYesNo
100,200,400​
3Customer BYesYesNoYesYes
100,200,400,500​
4Customer CNoYesYesNoNo
200,300​

What I need is a formula to extract the "Yes" answers into a comma separated string as per column G; so where answer is "yes" in line 2, (or whichever line the answer is on) bring back the code in line 1 for each column A to F. I have tried a number of nested IF statements but cant seem to get it right - any help will be greatly appreciated

Thanks

Simon
 

Excel Facts

Format cells as time
Select range and press Ctrl+Shift+2 to format cells as time. (Shift 2 is the @ sign).
What version of Excel are you using?

I suggest that you update your Account details (or click your user name at the top right of the forum) so helpers always know what Excel version(s) & platform(s) you are using as the best solution often varies by version. (Don’t forget to scroll down & ‘Save’)
 
Upvote 0
MrExcelPlayground16.xlsx
ABCDEFGH
1100200300400500Result 365Results (2016)
2Customer AYesYesNoYesNo100,200,400100,200,400
3Customer BYesYesNoYesYes100,200,400,500100,200,400,500
4Customer CNoYesYesNoNo200,300200,300
Sheet23
Cell Formulas
RangeFormula
G2:G4G2=TEXTJOIN(",",TRUE,FILTER($B$1:$F$1,B2:F2="Yes"))
H2:H4H2=LEFT(CONCAT(IF(B2:F2="Yes",$B$1:$F$1&",","")),LEN(CONCAT(IF(B2:F2="Yes",$B$1:$F$1&",","")))-1)
 
Upvote 0
Power Query Solution
Power Query:
let
    Source = Excel.CurrentWorkbook(){[Name="Table1"]}[Content],
    #"Unpivoted Other Columns" = Table.UnpivotOtherColumns(Source, {"Column1"}, "Attribute", "Value"),
    #"Grouped Rows" = Table.Group(#"Unpivoted Other Columns", {"Column1"}, {{"Data", each _, type table [Column1=text, Attribute=text, Value=text]}}),
    #"Added Custom" = Table.AddColumn(#"Grouped Rows", "Custom", each Table.AddIndexColumn([Data], "Index",1,1)),
    #"Removed Columns" = Table.RemoveColumns(#"Added Custom",{"Data"}),
    #"Expanded Custom" = Table.ExpandTableColumn(#"Removed Columns", "Custom", {"Attribute", "Value", "Index"}, {"Custom.Attribute", "Custom.Value", "Custom.Index"}),
    #"Filtered Rows" = Table.SelectRows(#"Expanded Custom", each ([Custom.Value] = "Yes")),
    #"Removed Columns1" = Table.RemoveColumns(#"Filtered Rows",{"Custom.Value"}),
    #"Pivoted Column" = Table.Pivot(Table.TransformColumnTypes(#"Removed Columns1", {{"Custom.Index", type text}}, "en-US"), List.Distinct(Table.TransformColumnTypes(#"Removed Columns1", {{"Custom.Index", type text}}, "en-US")[Custom.Index]), "Custom.Index", "Custom.Attribute"),
    #"Reordered Columns" = Table.ReorderColumns(#"Pivoted Column",{"Column1", "1", "2", "3", "4", "5"}),
    #"Merged Columns" = Table.CombineColumns(#"Reordered Columns",{"1", "2", "3", "4", "5"},Combiner.CombineTextByDelimiter(",", QuoteStyle.None),"Merged")
in
    #"Merged Columns"

Book2
ABCDEF
1Column1100200300400500
2Customer AYesYesNoYesNo
3Customer BYesYesNoYesYes
4Customer CNoYesYesNoNo
5
6Column1Merged
7Customer A100,200,,400,
8Customer B100,200,,400,500
9Customer C,200,300,,
Sheet1
 
Upvote 0

Forum statistics

Threads
1,215,248
Messages
6,123,873
Members
449,130
Latest member
lolasmith

We've detected that you are using an adblocker.

We have a great community of people providing Excel help here, but the hosting costs are enormous. You can help keep this site running by allowing ads on MrExcel.com.
Allow Ads at MrExcel

Which adblocker are you using?

Disable AdBlock

Follow these easy steps to disable AdBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the icon in the browser’s toolbar.
2)Click on the "Pause on this site" option.
Go back

Disable AdBlock Plus

Follow these easy steps to disable AdBlock Plus

1)Click on the icon in the browser’s toolbar.
2)Click on the toggle to disable it for "mrexcel.com".
Go back

Disable uBlock Origin

Follow these easy steps to disable uBlock Origin

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back

Disable uBlock

Follow these easy steps to disable uBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back
Back
Top