Forum Discussion

Anonymous's avatar
Anonymous
Not applicable
6 years ago
Solved

Split rows into multiple rows by line breaks

Hi guys,

 

Does anyone know if there is a way in Power Query Editor to split rows with line-broken data into multiple rows?

 

So that

 

Column1Column2
Diamond

A

B

C

Quartz

D

E

Pearl

F

G

H

 

Becomes

 

Column1Column2
DiamondA
Diamond

B

Diamond

C

Quartz

D

Quartz

E

Pearl

F

Pearl

G

Pearl

H

  • Nathaniel_C's avatar
    Nathaniel_C
    6 years ago

    Hi Anonymous ,
    Here is the pbix Split rows PBIX 
    So I split the 2nd col by delimiter. Which might be the only tricky part for you.  When I built a table to match yours I had to do a "Shift Enter" to get data on subsequent rows visually. You may have to play around with how to split the column, but from there it is easy, select first column and unpivot other rows, then delete attribute column.
    Let me know if you have any questions.

    If this solves your issues, please mark it as the solution, so that others can find it easily. Kudos πŸ‘are nice too.
    Nathaniel

     

7 Replies

  • Nathaniel_C's avatar
    Nathaniel_C
    Community Champion

    Hi Anonymous ,
    What do you mean by Line Broken Data? And are these two columns with the same name?
    Nathaniel

    • Anonymous's avatar
      Anonymous
      Not applicable

      Hi NathP ,

       

      I mean data where in one cell there's multiple lines of data, like in the tables above. And sorry, no, they were not meant to have the same name, I've now fixed that.

      • Nathaniel_C's avatar
        Nathaniel_C
        Community Champion

        Hello Anonymous ,
        Will send the pbix in a minute.

        Let me know if you have any questions.

        If this solves your issues, please mark it as the solution, so that others can find it easily. Kudos πŸ‘are nice too.
        Nathaniel

         

         





        From the Advanced Editor

        let
            Source = Table.FromRows(Json.Document(Binary.Decompress(Binary.FromText("i45WcslMzM3PS1HSUXKMyXOKyXNWitWJVgosTSwqqQIKusTkucbkuYEFA1ITi3KAYu4xeR5KsbEA", BinaryEncoding.Base64), Compression.Deflate)), let _t = ((type text) meta [Serialized.Text = true]) in type table [Column1 = _t, Column1.1 = _t]),
            #"Split Column by Delimiter" = Table.SplitColumn(Source, "Column1.1", Splitter.SplitTextByDelimiter("#(lf)", QuoteStyle.Csv), {"Column1.1.1", "Column1.1.2", "Column1.1.3"}),
            #"Changed Type" = Table.TransformColumnTypes(#"Split Column by Delimiter",{{"Column1", type text}, {"Column1.1.1", type text}, {"Column1.1.2", type text}, {"Column1.1.3", type text}}),
            #"Unpivoted Other Columns" = Table.UnpivotOtherColumns(#"Changed Type", {"Column1"}, "Attribute", "Value"),
            #"Removed Columns" = Table.RemoveColumns(#"Unpivoted Other Columns",{"Attribute"})
        in
            #"Removed Columns"