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

Get Fabric Certified for FREE during Fabric Data Days. Don't miss your chance! Learn more

Reply
Anonymous
Not applicable

How to Merge Queries by Column?

TABLE 1   
StoreNameProcessNameManagerNameGoodProductCount
Fish n Chips1Bill100
Fish n Chips2Steve125
Dave's Fish21Shannon100
Chum Bucket88Plankton32

 

TABLE 2   
StoreNameProcessNameManagerNameBadProductCount
Fish n Chips1Bill12
Fish n Chips1Tom200
Dave's Fish20Shane150
Happy Sushi11Shao85

 

DESIRED OUTPUT    
StoreNameProcessNameManagerNameGoodProductCountBadProductCount
Fish n Chips1Bill10012
Fish n Chips1Tom0200
Fish n Chips2Steve1250
Dave's Fish20Shane0150
Dave's Fish21Shannon1000
Chum Bucket88Plankton320
Happy Sushi11Shao085

 

I have tried using "Full Outer Join" to merge the two tables but when Table 2 data doesn't match ANY of the Table 1 data it leaves NULL values in the Output table for, "StoreName, ProcessName, MangerName". Thus only leaving the BadProductCount and NULL for everything else.

 

How can I merge Table 1 and Table 2 regardless if either table contains the same "StoreName, ProcessName, ManagerName" data?


 

 

4 REPLIES 4
v-yalanwu-msft
Community Support
Community Support

Hi @Anonymous  ,


According to you description, You could Append the two tables in power query, and then GroupBy the column. The steps are as follows:
Step1: Append two tables

v-yalanwu-msft_4-1620124692169.jpeg

Step2: Group By column

v-yalanwu-msft_5-1620124697117.jpeg

Step3: Replace values

v-yalanwu-msft_6-1620124702061.jpeg

The final output is shown below::

v-yalanwu-msft_7-1620124706399.png

In addition, M language is as follows:

let
Source = Table.FromRows(Json.Document(Binary.Decompress(Binary.FromText("i45WcssszlDIU3DOyCwoVtJRMgRip8ycHBDTwEApVgdDhREQB5eklqWClBiZgpW4JJalxpQaGBiZFyuAlIOUgUwKzkjMy8vPQzLMOaM0V8GpNDk7tQQoamEBJAJyEvOyS8CqjI2UYmMB", BinaryEncoding.Base64), Compression.Deflate)), let _t = ((type nullable text) meta [Serialized.Text = true]) in type table [StoreName = _t, ProcessName = _t, ManagerName = _t, GoodProductCount = _t]),
#"Changed Type" = Table.TransformColumnTypes(Source,{{"StoreName", type text}, {"ProcessName", Int64.Type}, {"ManagerName", type text}, {"GoodProductCount", Int64.Type}}),
#"Appended Query" = Table.Combine({#"Changed Type", Table2}),
#"Grouped Rows" = Table.Group(#"Appended Query", {"StoreName", "ProcessName", "ManagerName"}, {{"GoodProductCount", each List.Sum([GoodProductCount]), type nullable number}, {"BadProductCount", each List.Sum([BadProductCount]), type nullable number}}),
#"Replaced Value" = Table.ReplaceValue(#"Grouped Rows",null,0,Replacer.ReplaceValue,{"GoodProductCount", "BadProductCount"})
in
#"Replaced Value"

Best Regards,
Community Support Team_ Yalan Wu
If this post helps, then please consider Accept it as the solution to help the other members find it more quickly.

Anonymous
Not applicable

@amitchandak  The Append Queries Functionality just creates Duplicate data as shown below.

How can i resolve this?

Append Output    
StoreNameProcessNameManagerNameGoodProductCountBadProductCount
Fish n Chips1Bill100Null
Fish n Chips1BillNull12
Fish n Chips1TomNull200
Fish n Chips2Steve125Null
Dave's Fish20ShaneNull150
Dave's Fish21Shannon100Null
Chum Bucket88Plankton32Null
Happy Sushi11ShaoNull85

@Anonymous , that you can deal with by creating the aggregate table

 

refer: https://radacad.com/power-bi-aggregation-step-1-create-the-aggregated-table

Share with Power BI Enthusiasts: Full Power BI Video (20 Hours) YouTube
Microsoft Fabric Series 60+ Videos YouTube
Microsoft Fabric Hindi End to End YouTube
amitchandak
Super User
Super User

@Anonymous , Append in power query should do. It will append the same column and add a new column where the column name does not match

https://radacad.com/append-vs-merge-in-power-bi-and-power-query

Share with Power BI Enthusiasts: Full Power BI Video (20 Hours) YouTube
Microsoft Fabric Series 60+ Videos YouTube
Microsoft Fabric Hindi End to End YouTube

Helpful resources

Announcements
Fabric Data Days Carousel

Fabric Data Days

Advance your Data & AI career with 50 days of live learning, contests, hands-on challenges, study groups & certifications and more!

October Power BI Update Carousel

Power BI Monthly Update - October 2025

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

FabCon Atlanta 2026 carousel

FabCon Atlanta 2026

Join us at FabCon Atlanta, March 16-20, for the ultimate Fabric, Power BI, AI and SQL community-led event. Save $200 with code FABCOMM.

Top Solution Authors