Forum Discussion
Question related to combine a column with duplicated numbers into one cell containing several rows
- Jun 24, 2022
Well...
Until the MergedColumn step (included) this can be done with the UI so I suspect you're interested by step CombinedPartsAsLines that - in the way I did it - can't be done with the UI only
1/ Group the table by column [Job], Operation = All rows
2/ Go to the Advanced Editor. The Group Rows step says:
=Table.Group(MergedColumns, {"Job"}, {{"Parts", each _, type table [Job=nullable number, PartDescription=text]}})3/ Replace it with:
=Table.Group(MergedColumns, {"Job"}, {{"Parts", each Text.Combine([PartDescription], "#(lf)"), type text}})4/ Close the Advanced Editor (keep your changes)
What #3 does: take all values of column [PartDescription] and contenate them with a LineFeed char.
( the , type text at the end isn't mandatory)
Hi Excel
With your data formatted as table named Table1
Power Query code:
let
Source = Excel.CurrentWorkbook(){[Name="Table1"]}[Content],
ChangedType = Table.TransformColumnTypes(Source,{{"Job", type number}, {"Part Number", type text}}),
MergedColumns = Table.CombineColumns(ChangedType, {"Part Number", "Description"},
Combiner.CombineTextByDelimiter(" - ", QuoteStyle.None), "PartDescription"
),
CombinedPartsAsLines = Table.Group(MergedColumns, {"Job"},
{"Parts", each Text.Combine([PartDescription], "#(lf)"), type text}
)
in
CombinedPartsAsLines- ExcelJun 24, 2022Iron Contributor
Sir, Can you please explain code in Power Query?
Please..- LorenzoJun 24, 2022Silver Contributor
Well...
Until the MergedColumn step (included) this can be done with the UI so I suspect you're interested by step CombinedPartsAsLines that - in the way I did it - can't be done with the UI only
1/ Group the table by column [Job], Operation = All rows
2/ Go to the Advanced Editor. The Group Rows step says:
=Table.Group(MergedColumns, {"Job"}, {{"Parts", each _, type table [Job=nullable number, PartDescription=text]}})3/ Replace it with:
=Table.Group(MergedColumns, {"Job"}, {{"Parts", each Text.Combine([PartDescription], "#(lf)"), type text}})4/ Close the Advanced Editor (keep your changes)
What #3 does: take all values of column [PartDescription] and contenate them with a LineFeed char.
( the , type text at the end isn't mandatory)
- ExcelJun 24, 2022Iron ContributorThank you so much sir.