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
marketingVE
Frequent Visitor

Combining and merge two rows in one

Hi everyone!

 

I would to like to know if is possible to merge two rows of the different tables in the one row in power query,  for exemple:

 

I have this:

 

Origin       Name     Email                                Country     Age    Color

Table 1     Jhon       Jhon@outlook.com          Brazil            -          -

Table 2     Jhon       Jhon@outlook.com               -             25     Blue

 

But, i wuold like to have this:

 

 Name     Email                                Country     Age    Color

 Jhon       Jhon@outlook.com          Brazil          25     Blue

 

I'm just don't know how i do it!

 

My problem is similar with this : https://community.powerbi.com/t5/Desktop/Combining-rows-based-on-unique-id-and-combining-information...

 

But i don't understand this post very well. So please, help me!

 

PS: Sorry for my english, i'am just a brazilian young guy! 

 

 

 

 

1 ACCEPTED SOLUTION
Icey
Community Support
Community Support

Hi @marketingVE ,

 

You can also try this:

let
    Source = Table.FromRows(Json.Document(Binary.Decompress(Binary.FromText("i45WCklMyklVMFTSUfLKyM+DUg75pSU5+fnZesn5uUAhp6LEqswcIAOEYnVgmozwagIiI1OQ5pzSVCRNIJsccyshJPH24NICssUEbkssAA==", BinaryEncoding.Base64), Compression.Deflate)), let _t = ((type nullable text) meta [Serialized.Text = true]) in type table [Origin = _t, Name = _t, Email = _t, Country = _t, Age = _t, Color = _t]),
    #"Changed Type" = Table.TransformColumnTypes(Source,{{"Origin", type text}, {"Name", type text}, {"Email", type text}, {"Country", type text}, {"Age", Int64.Type}, {"Color", type text}}),
    #"Unpivoted Other Columns" = Table.UnpivotOtherColumns(#"Changed Type", {"Name", "Email", "Origin"}, "Attribute", "Value"),
    #"Filtered Rows" = Table.SelectRows(#"Unpivoted Other Columns", each ([Value] <> "")),
    #"Removed Columns" = Table.RemoveColumns(#"Filtered Rows",{"Origin"}),
    #"Pivoted Column" = Table.Pivot(#"Removed Columns", List.Distinct(#"Removed Columns"[Attribute]), "Attribute", "Value")
in
    #"Pivoted Column"

pivot.gif

 

 

Best Regards,

Icey

 

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

2 REPLIES 2
Icey
Community Support
Community Support

Hi @marketingVE ,

 

You can also try this:

let
    Source = Table.FromRows(Json.Document(Binary.Decompress(Binary.FromText("i45WCklMyklVMFTSUfLKyM+DUg75pSU5+fnZesn5uUAhp6LEqswcIAOEYnVgmozwagIiI1OQ5pzSVCRNIJsccyshJPH24NICssUEbkssAA==", BinaryEncoding.Base64), Compression.Deflate)), let _t = ((type nullable text) meta [Serialized.Text = true]) in type table [Origin = _t, Name = _t, Email = _t, Country = _t, Age = _t, Color = _t]),
    #"Changed Type" = Table.TransformColumnTypes(Source,{{"Origin", type text}, {"Name", type text}, {"Email", type text}, {"Country", type text}, {"Age", Int64.Type}, {"Color", type text}}),
    #"Unpivoted Other Columns" = Table.UnpivotOtherColumns(#"Changed Type", {"Name", "Email", "Origin"}, "Attribute", "Value"),
    #"Filtered Rows" = Table.SelectRows(#"Unpivoted Other Columns", each ([Value] <> "")),
    #"Removed Columns" = Table.RemoveColumns(#"Filtered Rows",{"Origin"}),
    #"Pivoted Column" = Table.Pivot(#"Removed Columns", List.Distinct(#"Removed Columns"[Attribute]), "Attribute", "Value")
in
    #"Pivoted Column"

pivot.gif

 

 

Best Regards,

Icey

 

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

Anonymous
Not applicable

all steps are performed via the GUI

 

let
    rec1=[f1="a",f2=null,f3=1],
    rec2=[f1="a",f2="b",f3=null],
    tfr=Table.FromRecords({rec1,rec2}),
    #"Intestazioni abbassate di livello" = Table.DemoteHeaders(tfr),
    #"Trasposta colonna" = Table.Transpose(#"Intestazioni abbassate di livello"),
    #"Aggiunta colonna personalizzata" = Table.AddColumn(#"Trasposta colonna", "merge", each [Column2]??[Column3]),
    #"Rimosse altre colonne" = Table.SelectColumns(#"Aggiunta colonna personalizzata",{"Column1", "merge"}),
    #"Trasposta colonna1" = Table.Transpose(#"Rimosse altre colonne"),
    #"Intestazioni alzate di livello" = Table.PromoteHeaders(#"Trasposta colonna1", [PromoteAllScalars=true])
in
    #"Intestazioni alzate di livello"

 

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.

Top Solution Authors