Power BI is turning 10, and we’re marking the occasion with a special community challenge. Use your creativity to tell a story, uncover trends, or highlight something unexpected.
Get startedJoin 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.
I have a SQL table loaded in PBI. I want to create my own primary keys and qualify them as keys in PBI.
The documentation on Table.ReplaceKeys is really bad. Can anyone explain how it works? Or is there another way of doing this?
Solved! Go to Solution.
Hi @richard-powerbi ,
It seems to change key, you could try below M code and refer to power-query-m-primer-part13-tables-table-think-ii and this post for details.
let
Source = #table(
{"CompanyID", "Name", "Location"},
{
{1, "ABC Company", "Chicago"},
{2, "ABC Company", "Charlotte"},
{3, "Some Other Company", "Cincinnati"}
}
),
KeysTagged = Table.AddKey(Source, {"CompanyID"}, true),
aa=Table.ReplaceKeys(
KeysTagged,
{
[Columns = {"Location"},
Primary = true]
}
)
in
Table.Keys(aa)
Best Regards,
Zoe Zhi
If this post helps, then please consider Accept it as the solution to help the other members find it more quickly.
Hi @richard-powerbi ,
It seems to change key, you could try below M code and refer to power-query-m-primer-part13-tables-table-think-ii and this post for details.
let
Source = #table(
{"CompanyID", "Name", "Location"},
{
{1, "ABC Company", "Chicago"},
{2, "ABC Company", "Charlotte"},
{3, "Some Other Company", "Cincinnati"}
}
),
KeysTagged = Table.AddKey(Source, {"CompanyID"}, true),
aa=Table.ReplaceKeys(
KeysTagged,
{
[Columns = {"Location"},
Primary = true]
}
)
in
Table.Keys(aa)
Best Regards,
Zoe Zhi
If this post helps, then please consider Accept it as the solution to help the other members find it more quickly.
Another question, is below code correct if I want two columns to act as one composite key? Both columns do not have unique values, only the combination of them is unique.
= Table.ReplaceKeys(Source, {[Columns = List.Combine({{"Column1"}, {"Column2"}), Primary = true]})
Later on I will merge on these two columns and I would like this utilize this for performance. Does above code work for this?
Anyone knows?
This is your chance to engage directly with the engineering team behind Fabric and Power BI. Share your experiences and shape the future.
Check out the June 2025 Power BI update to learn about new features.
User | Count |
---|---|
15 | |
12 | |
8 | |
8 | |
7 |
User | Count |
---|---|
15 | |
13 | |
9 | |
7 | |
6 |