Forum Discussion

Manasa55's avatar
Manasa55
Frequent Visitor
1 year ago

Automatically Establish the Relationship between Tables

Tried to establish the relationships between the tables automatically based on the same column name and data type in the power BI. Why this case is not working everytime. I changed the columns according to this and loaded the tables but the power bi doesn't automatically establish the relationship between the tables.

7 Replies

  • Hi Manasa55 

     

    Instead of relying on the the automatically detect relationship, why not set it up manually? As a best practice, we turn that feature off as oftentimes it creates unneeded relationships or those that are in the wrong direction or crossfiltering.

    • Manasa55's avatar
      Manasa55
      Frequent Visitor

      can't we able to create a relationship between tables using python script? 

      • danextian's avatar
        danextian
        Super User

        That isn't possible. You can to some extet use python to as a visual or as part of the ETL process but not to establish relationships.

  • v-kpoloju-msft's avatar
    v-kpoloju-msft
    Community Support

    Hi Manasa55,

    Thank you for reaching out to the Microsoft fabric community forum. Thankyou danextian, for his inputs on this thread.

    After reviewing the details you provided, I have identified few workarounds that may help resolve the issue. Please follow these steps:

    Creating relationships between tables using a Python script, while Power BI supports Python integration for data transformation within Power Query (via the "Run Python script" option), it does not allow defining data model relationships using Python. These relationships must be established manually in the model view or automatically during data load, depending on your settings. If you're looking to automate relationship creation, here are a few options.

     

    Power BI Desktop: Automatic relationship detection relies on heuristics such as column names, data types, and sometimes data values, which may not always be reliable. You can manually create relationships in the Model view for more control.

     

    Power BI XMLA Endpoint: For a Power BI dataset in a premium workspace, you could use Tabular Editor or scripting via XMLA/TOM (Tabular Object Model) to define relationships programmatically, though this requires tools like C# or PowerShell, not Python. In summary, Python scripting within Power BI is effective for data preparation, but not for data model editing, including relationship creation.

    Refer to the below link:
    Create and manage relationships in Power BI Desktop - Power BI | Microsoft Learn
    Run Python scripts in Power BI Desktop - Power BI | Microsoft Learn
    Use Python in Power BI Power Query Editor - Power BI | Microsoft Learn


    If this post helps, then please give us ‘Kudos’ and consider Accept it as a solution to help the other members find it more quickly.

    Thank you for using Microsoft Community Forum.

    • v-kpoloju-msft's avatar
      v-kpoloju-msft
      Community Support

      Hi Manasa55,

       

      May I ask if you have resolved this issue? If so, please mark the helpful reply and accept it as the solution. This will be helpful for other community members who have similar problems to solve it faster.

       

      Thank you.

      • v-kpoloju-msft's avatar
        v-kpoloju-msft
        Community Support

        Hi Manasa55,


        I wanted to check if you had the opportunity to review the information provided. Please feel free to contact us if you have any further questions. If my response has addressed your query, please accept it as a solution and give a 'Kudos' so other members can easily find it.
        Thank you.