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

July 7 - July 17 | Round 2 of the Power BI Dataviz World Championships. Don't miss your chance! Learn more

Reply
jeffshieldsdev
Solution Sage
Solution Sage

Anyone have experience with Table.AddKey() ?

I just learned about this function a few weeks ago, and I’m wondering:

1) should I always be using this before my merges? (Where I’m not already doing Table.Distinct() obviously) One would assume the Power Query engine would do this kind of optimization automatically.

2) can one assume there’s always a performance benefit to adding keys to both sides of the merge? Or if my fact table is super long, should I just AddKey() on my dimension table?

Thanks!
1 ACCEPTED SOLUTION
Anonymous
Not applicable

According to Chris Webb's blog post, Table.AddKey() seems to help only on the "lookup side" of a join.

 

If you use Table.Distinct() on a single column of a table, then it will automatically add a key to that column.

 

It appears that the performance benefit only occurs when using Aggregation, not Expanding.

 

This appears to be because Power Query defaults to a full cartesian cross when joining 2 tables.  When you aggregate, you'll see a great performance improvement.

 

Also, if you're joining with the intention of expanding a column...and you're expecting a single value on the join, consider using aggregation.  You could use Min or First to grab that single value, and you should atill get the speed improvement.

 

Let us know what your results are!

 

View solution in original post

3 REPLIES 3
Anonymous
Not applicable

According to Chris Webb's blog post, Table.AddKey() seems to help only on the "lookup side" of a join.

 

If you use Table.Distinct() on a single column of a table, then it will automatically add a key to that column.

 

It appears that the performance benefit only occurs when using Aggregation, not Expanding.

 

This appears to be because Power Query defaults to a full cartesian cross when joining 2 tables.  When you aggregate, you'll see a great performance improvement.

 

Also, if you're joining with the intention of expanding a column...and you're expecting a single value on the join, consider using aggregation.  You could use Min or First to grab that single value, and you should atill get the speed improvement.

 

Let us know what your results are!

 

ImkeF
Community Champion
Community Champion

Kudos to @Anonymous  explanation.

 

If you want to aggregate the joined table, then there are some performance aspects to consider: https://www.thebiccountant.com/2019/10/28/performance-tip-for-aggregations-after-joins-in-power-quer... 

 

But if you're joining distinct rows, then using the Key on the table is the only trick that I'm aware of.

In addition to that, make sure to check other factors that impact performance (especially the disabling of background refresh): https://www.thebiccountant.com/2019/10/28/performance-tip-for-aggregations-after-joins-in-power-quer... 

 

Imke Feldmann (The BIccountant)

If you liked my solution, please give it a thumbs up. And if I did answer your question, please mark this post as a solution. Thanks!

How to integrate M-code into your solution -- How to get your questions answered quickly -- How to provide sample data -- Check out more PBI- learning resources here -- Performance Tipps for M-queries

Greg_Deckler
Community Champion
Community Champion

@ImkeF might have some thoughts.

 

You could experiment. The Tools tab of the Query Editor ribbon has diagnostics now.



Follow on LinkedIn
@ me in replies or I'll lose your thread!!!
Instead of a Kudo, please vote for this idea
Become an expert!: Enterprise DNA
External Tools: MSHGQM
YouTube Channel!: Microsoft Hates Greg
Latest book!:
DAX For Humans

DAX is easy, CALCULATE makes DAX hard...

Helpful resources

Announcements
FabCon and SQLCon Barcelona 2026

FabCon & SQLCon – Barcelona 2026

Join us in Barcelona for FabCon and SQLCon, the Fabric, Power BI, SQL, and AI community event. Save €200 with code FABCMTY200.

60 days of Data Days Carousel

Data Days 2026

Join Data Days 2026: 60 days of free live/on-demand sessions, challenges, study groups, and certification opportunities.

Power BI DataViz World Championships carousel

Power BI DataViz World Championships - June 2026

A new Power BI DataViz World Championship is coming this June! Don't miss out on submitting your entry.

Top Solution Authors