Forum Discussion

engingee's avatar
engingee
Icon for Helper I rankHelper I
4 years ago
Solved

Is there any ways could split columns into rows, but not created duplicated value for other columns?

I have multiple colunms in a table, and I tried to created a colunms split into rows, and use that column as a filter for the table, but this step will create duplicate value for other colunms, so it...
  • Anonymous's avatar
    Anonymous
    4 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.