Forum Discussion

ishana's avatar
ishana
Regular Visitor
9 years ago
Solved

Merging 2 rows by splitting one column

Hey! I want to know how can I split my column in the following way 

I have data like:               s1  1   2    3

                                        s2  1   2    3

                                        s3  1   2    3

 

and what I want is   s1   s2   s3  1   2    3, all in one row. Is it possible to do this in power query ?

 

Thank You!

 

 

  • ishana,

     

    You may refer to the following code snippet.

    let
        Source = Table.FromRows(Json.Document(Binary.Decompress(Binary.FromText("i45WKjZUMFQwUjBWitUBcoyQOcYwTiwA", BinaryEncoding.Base64), Compression.Deflate)), let _t = ((type text) meta [Serialized.Text = true]) in type table [Column1 = _t]),
        #"Changed Type" = Table.TransformColumnTypes(Source,{{"Column1", type text}}),
        #"Split Column by Delimiter" = Table.ExpandListColumn(Table.TransformColumns(#"Changed Type", {{"Column1", Splitter.SplitTextByDelimiter(" ", QuoteStyle.Csv), let itemType = (type nullable text) meta [Serialized.Text = true] in type {itemType}}}), "Column1"),
        #"Removed Duplicates" = Table.Distinct(#"Split Column by Delimiter"),
        #"Sorted Rows" = Table.Sort(#"Removed Duplicates",{{"Column1", Order.Ascending}}),
        #"Transposed Table" = Table.Transpose(#"Sorted Rows")
    in
        #"Transposed Table"

5 Replies

  • ishana's avatar
    ishana
    Regular Visitor

    Hey! I want to know how can I split my column in the following way 

    I have data like:               s1  1   2    3

                                            s2  1   2    3

                                            s3  1   2    3

     

    and what I want is   s1   s2   s3  1   2    3, all in one row. Is it possible to do this in power query ?

     

    Thank You!

     

     

    • MarcelBeug's avatar
      MarcelBeug
      Icon for Community Champion rankCommunity Champion

      The following code gives you the values from column1 plus the other values from row 1 all in 1 row:

       

      = Table.FromRows({Table1[Column1]&List.Skip(Record.FieldValues(Table1{0}))})

       

       

      If this is not what you are looking for, please provide a better explanation.

  • Hey,

     it is ...

     

    I started with this table

     

    Than i selected the columns c1, c2, c3 and created a new column: Add column --> From Text --> Merge Columns

     

    Than I selected the column "pivot" and pivoted the Transform --> Any Column --> Pivot Column

     

    The result

     

    Due to the fact that "Pivot column" need a Value column I'm not sure if this will work for you, but maybe you will give it a try

     

    Regards


    ishana wrote:

    Hey! I want to know how can I split my column in the following way 

    I have data like:               s1  1   2    3

                                            s2  1   2    3

                                            s3  1   2    3

     

    and what I want is   s1   s2   s3  1   2    3, all in one row. Is it possible to do this in power query ?

     

    Thank You!

     

     


     

  • v-chuncz-msft's avatar
    v-chuncz-msft
    Icon for Community Support rankCommunity Support

    ishana,

     

    You may refer to the following code snippet.

    let
        Source = Table.FromRows(Json.Document(Binary.Decompress(Binary.FromText("i45WKjZUMFQwUjBWitUBcoyQOcYwTiwA", BinaryEncoding.Base64), Compression.Deflate)), let _t = ((type text) meta [Serialized.Text = true]) in type table [Column1 = _t]),
        #"Changed Type" = Table.TransformColumnTypes(Source,{{"Column1", type text}}),
        #"Split Column by Delimiter" = Table.ExpandListColumn(Table.TransformColumns(#"Changed Type", {{"Column1", Splitter.SplitTextByDelimiter(" ", QuoteStyle.Csv), let itemType = (type nullable text) meta [Serialized.Text = true] in type {itemType}}}), "Column1"),
        #"Removed Duplicates" = Table.Distinct(#"Split Column by Delimiter"),
        #"Sorted Rows" = Table.Sort(#"Removed Duplicates",{{"Column1", Order.Ascending}}),
        #"Transposed Table" = Table.Transpose(#"Sorted Rows")
    in
        #"Transposed Table"
    • MarcelBeug's avatar
      MarcelBeug
      Icon for Community Champion rankCommunity Champion

      ishana time for you to provide feedback!

      Either mark the appropriate solution as the solution, or provide more information if none of the solutions happens to be what you are looking for.