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
Anonymous
Not applicable

Append different columns from one table

Hello,

I have a table with four columns: A, B, C, D. 

<A>    <B>     <C>      <D>

John    Mike    Mark     Robyn

Maura Deb     Jim        Tim

 

I would like to create a new table with all the raws that include the relations between A and all of Columns B, C, D.

I would like to generate a new table with two columns including all the raws from the table with column A & B, append the same table with columns A & C and do the same with column A & D.

 

<A>      <New>

John      Mike

John      Mark

John      Robyn

Maura   Deb

Maura   Jim

Maura   Tim

 

I tried the funciton summarize and union but wasn't able to link the columns B, C, D to the new column.

 

Any chance you could help?

 

Thanks a lot !

1 ACCEPTED SOLUTION
v-lili6-msft
Community Support
Community Support

HI, @Anonymous 

The best way is Unpivot the columns in Edit Queries.

For example:

In Edit Queries, Selected Column B,C,D.

Then click Transform->Unpivot Columns

1.JPG

2.JPG

Now remove Attribute column.

Result:

3.JPG

 

here is M colde, please try it.

let
    Source = Table.FromRows(Json.Document(Binary.Decompress(Binary.FromText("i45W8srPyFPSUfLNzE4FUYlF2UAqKD+pMk8pVicaKFBalAgUcUlNApJemblAMgRIxsYCAA==", BinaryEncoding.Base64), Compression.Deflate)), let _t = ((type text) meta [Serialized.Text = true]) in type table [A = _t, B = _t, C = _t, D = _t]),
    #"Unpivoted Columns" = Table.UnpivotOtherColumns(Source, {"A"}, "Attribute", "Value"),
    #"Removed Columns" = Table.RemoveColumns(#"Unpivoted Columns",{"Attribute"})
in
    #"Removed Columns"

Best Regards,

Lin

Community Support Team _ Lin
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

1 REPLY 1
v-lili6-msft
Community Support
Community Support

HI, @Anonymous 

The best way is Unpivot the columns in Edit Queries.

For example:

In Edit Queries, Selected Column B,C,D.

Then click Transform->Unpivot Columns

1.JPG

2.JPG

Now remove Attribute column.

Result:

3.JPG

 

here is M colde, please try it.

let
    Source = Table.FromRows(Json.Document(Binary.Decompress(Binary.FromText("i45W8srPyFPSUfLNzE4FUYlF2UAqKD+pMk8pVicaKFBalAgUcUlNApJemblAMgRIxsYCAA==", BinaryEncoding.Base64), Compression.Deflate)), let _t = ((type text) meta [Serialized.Text = true]) in type table [A = _t, B = _t, C = _t, D = _t]),
    #"Unpivoted Columns" = Table.UnpivotOtherColumns(Source, {"A"}, "Attribute", "Value"),
    #"Removed Columns" = Table.RemoveColumns(#"Unpivoted Columns",{"Attribute"})
in
    #"Removed Columns"

Best Regards,

Lin

Community Support Team _ Lin
If this post helps, then please consider Accept it as the solution to help the other members find it more quickly.

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.