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

Power BI is turning 10! Let’s celebrate together with dataviz contests, interactive sessions, and giveaways. Register now.

Reply
ECorona
Frequent Visitor

What's the equivalent to FOREIGN KEY & REFERENCES in Power Query to create relationships from code?

I'm making a custom connector that consumes a rest API to create for tables that are in a linear way. The thing is that everytime the user loads the tables he needs to created the relationships by hand, so I'm trying to create the relationships from code using Power Query M to save time to my users. Is there an equivalent of MySQL's in Power Query M of this:

FOREIGN KEY (locationID) REFERENCES Locations(id)

 

So, my tables (reducing the example to only two tables): 

 

let
Locations= #table(
{"id", "location", "state","zipCode"},
{
{1, "Tehuacan", "Puebla","7200"},
{2, "Santa Ana", "Tlaxcala", "90300"},
{3, "Tijuana", "Baja California","22400"}
}
),
KeysTagged = Table.AddKey(Locations, {"id"}, true)
in
KeysTagged


let
Products= #table(
{"id", "date", "product","quantity","revenue","locationID"},
{
{1, "2/8/2023 9:30:10 PM", "Zapatos",10,5000,2},
{2, "4/18/2023 8:24:12 PM", "Cinturones",10,5689,2},
{3, "8/12/2023 4:08:23 PM", "Tennis",10,3467,3}
}
),
KeysTagged = Table.AddKey(Products, {"id"}, true)
in
KeysTagged

1 REPLY 1
lbendlin
Super User
Super User

 

 

 

so I'm trying to create the relationships from code using Power Query M to save time to my users

 

 

 

Power Query does not have such a concept.  All partitions are independently loaded into VertiPaq.

What you can do is name the join columns the same and hope for Power BI to make the right guesses.

 

lbendlin_0-1707609093332.png

 

You can also experiment with Table.AddKey and Table.Keys  to help with the suggestion.

Helpful resources

Announcements
Join our Fabric User Panel

Join our Fabric User Panel

This is your chance to engage directly with the engineering team behind Fabric and Power BI. Share your experiences and shape the future.

June 2025 Power BI Update Carousel

Power BI Monthly Update - June 2025

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

June 2025 community update carousel

Fabric Community Update - June 2025

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