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! Request now

Reply
markus_zhang
Advocate III
Advocate III

How to add two tables based on same columns

Hi experts,

 

This is an Excel 2016 case. I'm using Power Query to import two tables, after mashing up they have the following structure:

 

Main table:

 

Spot ID | Product A Impressions | Product B Impressions | ... | (So on may have 20-30 products)

 

Secondary table:

 

Spot ID | Product E Impressions | Product K Impressions

 

Question:

 

All spots in secondary table (about 50-75) are in main table (about 2,000+), is it possible to use Power Query or Power Pivot to add the impressions in secondary table to the same columns of main table?

For example if in secondary table we have a spot id 12345 having impression 100 for Product E, and in the main table the same spot has 900 for same product, now I want to create a new table, with the same structure of the Main table (and have all spots present), but have 1,000 impressions for 12345 on Product E.

 

Thank you!

1 ACCEPTED SOLUTION
v-jiascu-msft
Microsoft Employee
Microsoft Employee

Hi @markus_zhang,

 

We can do it with some built-in functions. Please refer to the snapshot below and the demo in the attachment. 

How-to-add-two-tables-based-on-same-columns

1. Append them together. 

2. Group by the [Spot ID].

 

Best Regards,
Dale

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

4 REPLIES 4
markus_zhang
Advocate III
Advocate III

Final Solution:

For anyone who might find this post useful, in the future, I'll provide the final solution.

Instead of suing Power Query, I use Python + pandas to solve the problem, the line of code that really handles the job looks like this:

 

Result = Result.groupby('spot id', sort = None).sum().reset_index()

Basically Result (before this line) is the appended version, and then groupby().sum() will add up based on same value of [spot id].

Thanks for sharing, @markus_zhang.

 

 

Best Regards,
Dale

Community Support Team _ Dale
If this post helps, then please consider Accept it as the solution to help the other members find it more quickly.
v-jiascu-msft
Microsoft Employee
Microsoft Employee

Hi @markus_zhang,

 

We can do it with some built-in functions. Please refer to the snapshot below and the demo in the attachment. 

How-to-add-two-tables-based-on-same-columns

1. Append them together. 

2. Group by the [Spot ID].

 

Best Regards,
Dale

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

Thanks Dale, will accept as solution.

 

It seems that GROUP BY will automatically remove any column that is not in the list, so this poses one problem - I have about 200+ columns so it's kind of clumsy to add all of them into GROUP BY. 

 

Second question, is it possible to directly GROUP on the same column instead of creating new ones?

 

Thank you!

 

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