Skip to main content
cancel
Showing results for 
Search instead for 
Did you mean: 

Register now to learn Fabric in free live sessions led by the best Microsoft experts. From Apr 16 to May 9, in English and Spanish.

Reply
ishana
Regular Visitor

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!

 

 

1 ACCEPTED SOLUTION
v-chuncz-msft
Community Support
Community 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"
Community Support Team _ Sam Zha
If this post helps, then please consider Accept it as the solution to help the other members find it more quickly.

View solution in original post

5 REPLIES 5
v-chuncz-msft
Community Support
Community 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"
Community Support Team _ Sam Zha
If this post helps, then please consider Accept it as the solution to help the other members find it more quickly.

@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.

Specializing in Power Query Formula Language (M)
TomMartens
Super User
Super User

Hey,

 it is ...

 

I started with this table

2017-08-11_1-13-22.png

 

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

2017-08-11_1-17-49.png

 

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

2017-08-11_1-21-33.png

 

The result

2017-08-11_1-23-32.png

 

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!

 

 


 



Did I answer your question? Mark my post as a solution, this will help others!

Proud to be a Super User!
I accept Kudos 😉
Hamburg, Germany
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!

 

 

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.

Specializing in Power Query Formula Language (M)

Helpful resources

Announcements
Microsoft Fabric Learn Together

Microsoft Fabric Learn Together

Covering the world! 9:00-10:30 AM Sydney, 4:00-5:30 PM CET (Paris/Berlin), 7:00-8:30 PM Mexico City

PBI_APRIL_CAROUSEL1

Power BI Monthly Update - April 2024

Check out the April 2024 Power BI update to learn about new features.

April Fabric Community Update

Fabric Community Update - April 2024

Find out what's new and trending in the Fabric Community.