Forum Discussion

Coby's avatar
Coby
New Member
2 years ago

How to prepare multiple rows with two different colums

Hy, 
I would kindly ask your help. I have a table with many columns from SQL database. This database contain one colum which contain two ore more ID spearated with " ; " (semicolons). I can split column to separate columns. However I do not know how can I prepare multiple rows (other column data should be the same but the ID column sholud be different in Power Query?

 

Original table:

IDData 1Data 2
1000; 1001ab
1002cd
1003; 1004; 1005ef

 

My actual stage: (with split colum)

ID1ID2ID3Data 1Data 2
10001001 ab
1002  cd
100310041005ef

 

Neaded table:

IDData 1Data 2
1000ab
1001ab
1002cd
1003ef
1004ef
1005ef

 

Best regards,

Coby

4 Replies

  • wdx223_Daniel's avatar
    wdx223_Daniel
    Community Champion

    =#table(Table.ColumnNames(OriginalTable),List.TransformMany(Table.ToRows(OriginalTable),each Text.Split(_{0},";"),(x,y)=>{y}&List.Skip(x)))

  • Coby's avatar
    Coby
    New Member

    Thanks. It is work.

    Could you please define the column where should only split the data by ";" . I have other columns which contain ";" as well, but I would not split those. 

  • Subash_Govind's avatar
    Subash_Govind
    Frequent Visitor

    Below are the results code...

    let
    Source = Table.FromRows(Json.Document(Binary.Decompress(Binary.FromText("i45W8nRR0lFySSxJVDCEMYyUYnWilQwNDAysFYAkSDwRiJNgwkZATjIQp8AEjMHqTMCkKVAiFYjTlGJjAQ==", BinaryEncoding.Base64), Compression.Deflate)), let _t = ((type nullable text) meta [Serialized.Text = true]) in type table [#"(blank)" = _t, #"(blank).1" = _t, #"(blank).2" = _t]),
    #"Changed Type" = Table.TransformColumnTypes(Source,{{"(blank)", type text}, {"(blank).1", type text}, {"(blank).2", type text}}),
    #"Promoted Headers" = Table.PromoteHeaders(#"Changed Type", [PromoteAllScalars=true]),
    #"Changed Type1" = Table.TransformColumnTypes(#"Promoted Headers",{{"ID", type text}, {"Data 1", type text}, {"Data 2", type text}}),
    #"Split Column by Delimiter" = Table.SplitColumn(#"Changed Type1", "ID", Splitter.SplitTextByDelimiter(";", QuoteStyle.Csv), {"ID.1", "ID.2", "ID.3"}),
    #"Changed Type2" = Table.TransformColumnTypes(#"Split Column by Delimiter",{{"ID.1", Int64.Type}, {"ID.2", Int64.Type}, {"ID.3", Int64.Type}}),
    #"Unpivoted Columns" = Table.UnpivotOtherColumns(#"Changed Type2", {"Data 1", "Data 2"}, "Attribute", "ID"),
    #"Removed Columns" = Table.RemoveColumns(#"Unpivoted Columns",{"Attribute"}),
    #"Reordered Columns" = Table.ReorderColumns(#"Removed Columns",{"ID", "Data 1", "Data 2"})
    in
    #"Reordered Columns"