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

How to merge or append views ?

Hello, 

 

I have 2 PostgreSQL views. I have made a sample data below for reference. 

What I want is to get the desired result posted below for these 2 tables, remember column names in both the rows are different but has the same value in it(which I can change to append).

Table 1 

Name AgeSalary
A2010000
B3020000
C4030000

 

Table 2

Name_textAge_NumberAddress_valueGender_text
A X1M
D50Y1M
E60Z1F

 

Desired Result

Name AgeAddress_valueGender_textSalary
A20X1M10000
B30  20000
C40  30000
D50Y1M 
E60Z1F 

 

Result I am getting when appending is. 

Name AgeAddress_valueGender_textSalaryAge_Number
A20  10000 
B30  20000 
C40  30000 
D Y1M 50
E Z1F 60
A X1M  

 

I dont want duplicate rows, I can change column names and then append but then the result I am getting is this - 

Name AgeAddress_valueGender_textSalary
A20  10000
B30  20000
C40  30000
D50Y1M 
E60Z1F 
A X1M 

 

Can someone please help on this, I cannot use KNIME or alteryx. Just have to use Power Query or dax to get this solved.

Plus I have used merging queries and it is not working.

 

Thanks 

1 ACCEPTED SOLUTION
MFelix
Super User
Super User

Hi @Anonymous ,

 

You need to first do a merge to get the value on the lines where there are commons values like line A and then the append and finally remove duplicates on the first column

 

Check code below for both tables) and PBIX file attach, be aware that you may need to make some changes to the way the merge is made.

// Table
let
    Source = Table.FromRows(Json.Document(Binary.Decompress(Binary.FromText("i45WclTSUTIyABKGBkCgFKsTreQE5BkbgMVhQs5AnokBWBwsFAsA", BinaryEncoding.Base64), Compression.Deflate)), let _t = ((type nullable text) meta [Serialized.Text = true]) in type table [#"Name" = _t, Age = _t, Salary = _t]),
    #"Changed Type" = Table.TransformColumnTypes(Source,{{"Name", type text}, {"Age", Int64.Type}, {"Salary", Int64.Type}}),
    #"Merged Queries" = Table.NestedJoin(#"Changed Type", {"Name"}, #"Table (2)", {"Name"}, "Table (2)", JoinKind.FullOuter),
    #"Expanded Table (2)" = Table.ExpandTableColumn(#"Merged Queries", "Table (2)", {"Address_value", "Gender_text"}, {"Address_value", "Gender_text"}),
    #"Filtered Rows" = Table.SelectRows(#"Expanded Table (2)", each ([#"Name"] <> null)),
    #"Appended Query" = Table.Combine({#"Filtered Rows", #"Table (2)"}),
    #"Removed Duplicates" = Table.Distinct(#"Appended Query", {"Name"})
in
    #"Removed Duplicates"

// Table (2)
let
    Source = Table.FromRows(Json.Document(Binary.Decompress(Binary.FromText("i45WclTSUVIA4ghDIOGrFKsTreQCZJkaAIlIhJgrkGUGEosCibkpxcYCAA==", BinaryEncoding.Base64), Compression.Deflate)), let _t = ((type nullable text) meta [Serialized.Text = true]) in type table [Name_text = _t, Age_Number = _t, Address_value = _t, Gender_text = _t]),
    #"Changed Type" = Table.TransformColumnTypes(Source,{{"Name_text", type text}, {"Age_Number", Int64.Type}, {"Address_value", type text}, {"Gender_text", type text}}),
    #"Renamed Columns" = Table.RenameColumns(#"Changed Type",{{"Name_text", "Name"}, {"Age_Number", "Age"}})
in
    #"Renamed Columns"

 


Regards

Miguel Félix


Did I answer your question? Mark my post as a solution!

Proud to be a Super User!

Check out my blog: Power BI em Português



View solution in original post

1 REPLY 1
MFelix
Super User
Super User

Hi @Anonymous ,

 

You need to first do a merge to get the value on the lines where there are commons values like line A and then the append and finally remove duplicates on the first column

 

Check code below for both tables) and PBIX file attach, be aware that you may need to make some changes to the way the merge is made.

// Table
let
    Source = Table.FromRows(Json.Document(Binary.Decompress(Binary.FromText("i45WclTSUTIyABKGBkCgFKsTreQE5BkbgMVhQs5AnokBWBwsFAsA", BinaryEncoding.Base64), Compression.Deflate)), let _t = ((type nullable text) meta [Serialized.Text = true]) in type table [#"Name" = _t, Age = _t, Salary = _t]),
    #"Changed Type" = Table.TransformColumnTypes(Source,{{"Name", type text}, {"Age", Int64.Type}, {"Salary", Int64.Type}}),
    #"Merged Queries" = Table.NestedJoin(#"Changed Type", {"Name"}, #"Table (2)", {"Name"}, "Table (2)", JoinKind.FullOuter),
    #"Expanded Table (2)" = Table.ExpandTableColumn(#"Merged Queries", "Table (2)", {"Address_value", "Gender_text"}, {"Address_value", "Gender_text"}),
    #"Filtered Rows" = Table.SelectRows(#"Expanded Table (2)", each ([#"Name"] <> null)),
    #"Appended Query" = Table.Combine({#"Filtered Rows", #"Table (2)"}),
    #"Removed Duplicates" = Table.Distinct(#"Appended Query", {"Name"})
in
    #"Removed Duplicates"

// Table (2)
let
    Source = Table.FromRows(Json.Document(Binary.Decompress(Binary.FromText("i45WclTSUVIA4ghDIOGrFKsTreQCZJkaAIlIhJgrkGUGEosCibkpxcYCAA==", BinaryEncoding.Base64), Compression.Deflate)), let _t = ((type nullable text) meta [Serialized.Text = true]) in type table [Name_text = _t, Age_Number = _t, Address_value = _t, Gender_text = _t]),
    #"Changed Type" = Table.TransformColumnTypes(Source,{{"Name_text", type text}, {"Age_Number", Int64.Type}, {"Address_value", type text}, {"Gender_text", type text}}),
    #"Renamed Columns" = Table.RenameColumns(#"Changed Type",{{"Name_text", "Name"}, {"Age_Number", "Age"}})
in
    #"Renamed Columns"

 


Regards

Miguel Félix


Did I answer your question? Mark my post as a solution!

Proud to be a Super User!

Check out my blog: Power BI em Português



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