Can you help with concatenation?

frank265

New Member
Joined
Feb 5, 2013
Messages
33
Office Version
  1. 365
Platform
  1. MacOS
Hi, I have a spreadsheet like the one below with data in the first two columns. I am trying to achieve the data in the third column. Currently I am doing this through manual concatenation, i.e. typing =concatenate(B1,",",B2,",",B3). etc. This is quite time consuming and prone to errors when working with a lot of data.

Is there a way to automate this, so excel can find each unique product and concatenate the relevant recipe. Or is there a better formula other than concatenation?

NB, it doesn't matter what seperates each recipe (comma, semi colon, pipe symbol etc), but there has to be a seperator as this is needed to identify each record later when importing to another system.

I would be super grateful for any help with this.

Thanks so much for reading.

Frank

ProductRecipes Using this ProductAll Recipes Using Product
Chilli OilChilli Con CarneChilli Con Carne,Spaghetti Bolognese,Egg Fried Rice
Spaghetti Bolognese
Egg Fried Rice
Avokado OilAvokado SaladAvokado Salad,Mozzarella Salad
Mozzarella Salad
Groundnut OilStewed ChickenStewed Chicken
Rapeseed OilZucchini FrittersZucchini Fritters,Plantain,Omelete
Plantain
Omelete
 

Excel Facts

Waterfall charts in Excel?
Office 365 customers have access to Waterfall charts since late 2016. They were added to Excel 2019.
Using Power Query

Rich (BB code):
let
    Source = Excel.CurrentWorkbook(){[Name="Table3"]}[Content],
    #"Changed Type" = Table.TransformColumnTypes(Source,{{"Product", type text}, {"Recipes Using this Product", type text}}),
    #"Filled Down" = Table.FillDown(#"Changed Type",{"Product"}),
    #"Grouped Rows" = Table.Group(#"Filled Down", {"Product"}, {{"Data", each _, type table [Product=text, Recipes Using this Product=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", {"Product", "Recipes Using this Product", "Index"}, {"Custom.Product", "Custom.Recipes Using this Product", "Custom.Index"}),
    #"Removed Columns1" = Table.RemoveColumns(#"Expanded Custom",{"Custom.Product"}),
    #"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.Recipes Using this Product"),
    #"Merged Columns" = Table.CombineColumns(#"Pivoted Column",{"1", "2", "3"},Combiner.CombineTextByDelimiter(", ", QuoteStyle.None),"All Recipes Using Product")
in
    #"Merged Columns"

Book12
AB
1ProductAll Recipes Using Product
2Avokado OilAvokado Salad, Mozzarella Salad,
3Chilli OilChilli Con Carne, Spaghetti Bolognese, Egg Fried Rice
4Groundnut OilStewed Chicken, ,
5Rapeseed OilZucchini Fritters, Plantain, Omelete
Sheet4
 
Upvote 0
Using Power Query

Rich (BB code):
let
    Source = Excel.CurrentWorkbook(){[Name="Table3"]}[Content],
    #"Changed Type" = Table.TransformColumnTypes(Source,{{"Product", type text}, {"Recipes Using this Product", type text}}),
    #"Filled Down" = Table.FillDown(#"Changed Type",{"Product"}),
    #"Grouped Rows" = Table.Group(#"Filled Down", {"Product"}, {{"Data", each _, type table [Product=text, Recipes Using this Product=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", {"Product", "Recipes Using this Product", "Index"}, {"Custom.Product", "Custom.Recipes Using this Product", "Custom.Index"}),
    #"Removed Columns1" = Table.RemoveColumns(#"Expanded Custom",{"Custom.Product"}),
    #"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.Recipes Using this Product"),
    #"Merged Columns" = Table.CombineColumns(#"Pivoted Column",{"1", "2", "3"},Combiner.CombineTextByDelimiter(", ", QuoteStyle.None),"All Recipes Using Product")
in
    #"Merged Columns"

Book12
AB
1ProductAll Recipes Using Product
2Avokado OilAvokado Salad, Mozzarella Salad,
3Chilli OilChilli Con Carne, Spaghetti Bolognese, Egg Fried Rice
4Groundnut OilStewed Chicken, ,
5Rapeseed OilZucchini Fritters, Plantain, Omelete
Sheet4

Thanks so much, this looks like exactly what I want to achieve. I am totally new to Power Query, never used it before. Is there a way to copy this formula and implement it on my spreadsheet?
 
Upvote 0
I suggest that you update your Account details (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’)

Until then, assuming that you have Excel 365 or Excel 2019 try this

20 07 06.xlsm
ABC
1ProductRecipes Using this ProductAll Recipes Using Product
2Chilli OilChilli Con CarneChilli Con Carne,Spaghetti Bolognese,Egg Fried Rice
3Spaghetti Bolognese 
4Egg Fried Rice 
5Avokado OilAvokado SaladAvokado Salad,Mozzarella Salad
6Mozzarella Salad 
7Groundnut OilStewed ChickenStewed Chicken
8Rapeseed OilZucchini FrittersZucchini Fritters,Plantain,Omelete
9Plantain 
10Omelete 
11
Concat
Cell Formulas
RangeFormula
C2:C10C2=IF(A2="","",IF(A3<>"",B2,TEXTJOIN(",",1,B2:INDEX(B3:B$2000,IFERROR(MATCH("?*",A3:A$2000,0)-1,ROWS(A3:A$2000))))))
 
Upvote 0
I suggest that you update your Account details (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’)

Until then, assuming that you have Excel 365 or Excel 2019 try this

20 07 06.xlsm
ABC
1ProductRecipes Using this ProductAll Recipes Using Product
2Chilli OilChilli Con CarneChilli Con Carne,Spaghetti Bolognese,Egg Fried Rice
3Spaghetti Bolognese 
4Egg Fried Rice 
5Avokado OilAvokado SaladAvokado Salad,Mozzarella Salad
6Mozzarella Salad 
7Groundnut OilStewed ChickenStewed Chicken
8Rapeseed OilZucchini FrittersZucchini Fritters,Plantain,Omelete
9Plantain 
10Omelete 
11
Concat
Cell Formulas
RangeFormula
C2:C10C2=IF(A2="","",IF(A3<>"",B2,TEXTJOIN(",",1,B2:INDEX(B3:B$2000,IFERROR(MATCH("?*",A3:A$2000,0)-1,ROWS(A3:A$2000))))))
THANK YOU, THANK YOU, THANK YOU! That worked a charm. So grateful for the help, it's saved me a lot of time and nice that this will now be more accurate. Thanks again & I have updated my profile as advised. Hope you have a great day ahead :)
 
Upvote 0
You're welcome - glad it worked for you. :)

.. and thanks for the profile update. (y)
 
Upvote 0
With your worksheet open. Go to Data Tab. HIghlight your table. On Get and Transform. From Table/Range. Once the PQ editor opens. View. Advance Editor. Paste my Mcode into the Editor replacing what is there. Close and Load on the Home Tab.

Check out the link in my signature for more information and guidelines.
 
Upvote 0

Forum statistics

Threads
1,214,653
Messages
6,120,750
Members
448,989
Latest member
mariah3

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