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

Get certified in Microsoft Fabric—for free! For a limited time, get a free DP-600 exam voucher to use by the end of 2024. Register now

Reply
RokuCap
Helper I
Helper I

Merging Two Tables - Keep Order of Rows from Secondary Table in the Merged Table

I have two tables: Table A & Table B. I want to merge the Table B values to Table A but keep the row order from Table B (merging messes the row ordering). I've created a Group Rank column (based on the Category value) as a helper column for the merge.

Any help would be greatly appreciated!

Table A

IndexCategoryDescriptionPrice ($/kg)
1Cat AApples5
2Cat BOranges2
3Cat CPears3
4Cat DWatermelon4

Table B

Group RankCategoryOrder ID
1Cat A77381
2Cat A71329
3Cat A61086
1Cat C52255
2Cat C68071

 

Desired Merge Result:

CategoryDescriptionPrice ($/kg)Group RankOrder ID
Cat AApples5177381
Cat AApples5271329
Cat AApples5361086
Cat BOranges2  
Cat CPears3152255
Cat CPears3268071
Cat DWatermelon4  

 

Extra question: I'd also like the price value to only show on the 1st instance of the Category (Group Rank: 1) and be null or zero for rows after with the same value. Is this achievable in PQ?

1 ACCEPTED SOLUTION
v-yalanwu-msft
Community Support
Community Support

Hi, @RokuCap ;

After we merge two table, we could sort the column.

 

= Table.Sort(#"Expanded TableB",{{"Index", Order.Ascending}, {"TableB.Group Rank", Order.Ascending}})

 

vyalanwumsft_0-1669605458985.pngvyalanwumsft_1-1669605470899.png

Then the final show:

vyalanwumsft_0-1669605578525.png


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.

View solution in original post

3 REPLIES 3
v-yalanwu-msft
Community Support
Community Support

Hi, @RokuCap ;

After we merge two table, we could sort the column.

 

= Table.Sort(#"Expanded TableB",{{"Index", Order.Ascending}, {"TableB.Group Rank", Order.Ascending}})

 

vyalanwumsft_0-1669605458985.pngvyalanwumsft_1-1669605470899.png

Then the final show:

vyalanwumsft_0-1669605578525.png


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.

Thanks Yalan. This did the trick!

Luis98
Resolver II
Resolver II

Hi @RokuCap ,

 

What if you add an index column to Table B before the merge, and then order the merged table by index column?

Helpful resources

Announcements
November Carousel

Fabric Community Update - November 2024

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

Live Sessions with Fabric DB

Be one of the first to start using Fabric Databases

Starting December 3, join live sessions with database experts and the Fabric product team to learn just how easy it is to get started.

Las Vegas 2025

Join us at the Microsoft Fabric Community Conference

March 31 - April 2, 2025, in Las Vegas, Nevada. Use code MSCUST for a $150 discount! Early Bird pricing ends December 9th.

Nov PBI Update Carousel

Power BI Monthly Update - November 2024

Check out the November 2024 Power BI update to learn about new features.