Forum Discussion
Is there any ways could split columns into rows, but not created duplicated value for other columns?
- Anonymous4 years ago
Hi engingee ,
You can group by to create index columns and then create an if statement to get the result.
Input:
Output:
let Source = Table.FromRows(Json.Document(Binary.Decompress(Binary.FromText("i45WMlTSUTLUN9I31jfRN1WK1YlWMgKKgHn6ZmC+MViFMZBvoRQbCwA=", BinaryEncoding.Base64), Compression.Deflate)), let _t = ((type nullable text) meta [Serialized.Text = true]) in type table [Column1 = _t, Column2 = _t]), #"Changed Type" = Table.TransformColumnTypes(Source,{{"Column1", Int64.Type}, {"Column2", type text}}), #"Split Column by Delimiter" = Table.ExpandListColumn(Table.TransformColumns(#"Changed Type", {{"Column2", Splitter.SplitTextByDelimiter("/", QuoteStyle.Csv), let itemType = (type nullable text) meta [Serialized.Text = true] in type {itemType}}}), "Column2"), #"Grouped Rows" = Table.Group(#"Split Column by Delimiter", {"Column1"}, {{"Count", each _, type table [Column1=nullable number, Column2=nullable text]}}), #"Added Custom" = Table.AddColumn(#"Grouped Rows", "Custom", each Table.AddIndexColumn([Count],"Index",1)), #"Removed Columns" = Table.RemoveColumns(#"Added Custom",{"Count"}), #"Expanded Custom" = Table.ExpandTableColumn(#"Removed Columns", "Custom", {"Column2", "Index"}, {"Column2", "Index"}), #"Added Custom1" = Table.AddColumn(#"Expanded Custom", "Custom", each if [Index]=1 then [Column1] else null), #"Removed Columns1" = Table.RemoveColumns(#"Added Custom1",{"Column1"}), #"Reordered Columns" = Table.ReorderColumns(#"Removed Columns1",{"Custom", "Column2", "Index"}), #"Removed Columns2" = Table.RemoveColumns(#"Reordered Columns",{"Index"}) in #"Removed Columns2"Best Regards,
Stephen Tao
If this post helps, then please consider Accept it as the solution to help the other members find it more quickly.
Hi,
in power query you can easily transform
to
only by splitting by column
If this post is useful to help you to solve your issue consider giving the post a thumbs up
and accepting it as a solution !
is that possible to have a result like table 2 rather than table 3 please?
- serpiva644 years ago
Solution Sage
Hi, one possibility to achieve this is:
split column by delimiter to columns
then select column 1 and unpivot other columns
You obtain this
now you add a custom column
and then you need only to reorder columns and change name.