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

Join us for an expert-led overview of the tools and concepts you'll need to become a Certified Power BI Data Analyst and pass exam PL-300. Register now.

Reply
JW_pfsc
New Member

Combine two tables with both unique and duplicate values

Hi all

 

I'm trying to combine two tables with matching columns into a third table. The column "Item ID" contains ID numbers which may exist only in table 1 (222), only in table 2 (333), or in both table 1 and 2 (111 & 444).

 

The location of each item may be the same in both tables, or it may be different. So I'm trying to create "combined table" in the image below, from table 1 and table 2. Can anyone give me any pointers to acheive this?

 

Thanks in advance.

 

JW_pfsc_0-1691665816436.png

 

3 REPLIES 3
JW_pfsc
New Member

Hi @Idrissshatila 

 

Thank you for the suggestion. I tried doing this originally, but found it didn't acheive the desired result. If I created a merged query (full outer), the table 2 item ID's were in a different column to the table 1 item ID's. So in my example above, the table looked like this...

 

JW_pfsc_0-1691671405212.png

 

I'd like to have an "Item ID" slicer, where I can filter by Item ID and see it's respective location in table 1 and table 2. In the example above, "333" isn't in the Item ID slicer for obvious reasons.

 

Thanks,

Anonymous
Not applicable

Hi @JW_pfsc 

You can create two blank query in power query, and put the following code to Advanced Editor in power query.

let
    Source = Table.FromRows(Json.Document(Binary.Decompress(Binary.FromText("i45WMjQ0VNJRclKK1YlWMjY2BrJdwGwTExMg21UpNhYA", BinaryEncoding.Base64), Compression.Deflate)), let _t = ((type nullable text) meta [Serialized.Text = true]) in type table [#"Item ID" = _t, #"Location " = _t]),
    #"Changed Type" = Table.TransformColumnTypes(Source,{{"Item ID", Int64.Type}, {"Location ", type text}})
in
    #"Changed Type"
let
    Source = Table.FromRows(Json.Document(Binary.Decompress(Binary.FromText("i45WMjQ0VNJRclSK1YlWMjIyArKdwWwTExMg21UpNhYA", BinaryEncoding.Base64), Compression.Deflate)), let _t = ((type nullable text) meta [Serialized.Text = true]) in type table [#"Item ID" = _t, Location = _t]),
    #"Changed Type" = Table.TransformColumnTypes(Source,{{"Item ID", Int64.Type}, {"Location", type text}}),
    #"Merged Queries" = Table.NestedJoin(#"Changed Type", {"Item ID"}, Query1, {"Item ID"}, "Table (2)", JoinKind.FullOuter),
    #"Expanded Table (2)" = Table.ExpandTableColumn(#"Merged Queries", "Table (2)", {"Item ID", "Location "}, {"Item ID.1", "Location "}),
    #"Added Custom" = Table.AddColumn(#"Expanded Table (2)", "Custom", each if [Item ID]=null then [Item ID.1] else [Item ID]),
    #"Removed Columns" = Table.RemoveColumns(#"Added Custom",{"Item ID", "Item ID.1"}),
    #"Reordered Columns" = Table.ReorderColumns(#"Removed Columns",{"Custom", "Location", "Location "}),
    #"Sorted Rows" = Table.Sort(#"Reordered Columns",{{"Custom", Order.Ascending}})
in
    #"Sorted Rows"

vxinruzhumsft_0-1693292340525.png

Best Regards!

Yolo Zhu

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

Idrissshatila
Super User
Super User

Hello @JW_pfsc ,

 

yes, you can do that through Merge queries in Power Query where you select the join full outer.

 

check this documentation to learn how to merge both queries https://learn.microsoft.com/en-us/power-query/merge-queries-overview

 

If I answered your question, please mark my post as solution, Appreciate your Kudos 👍

Follow me on Linkedin



Did I answer your question? Mark my post as a solution! Appreciate your Kudos
Follow me on LinkedIn linkedIn
Vote for my Community Mobile App Idea

Proud to be a Super User!




Helpful resources

Announcements
Join our Fabric User Panel

Join our Fabric User Panel

This is your chance to engage directly with the engineering team behind Fabric and Power BI. Share your experiences and shape the future.

June 2025 Power BI Update Carousel

Power BI Monthly Update - June 2025

Check out the June 2025 Power BI update to learn about new features.

June 2025 community update carousel

Fabric Community Update - June 2025

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