Forum Discussion

Carl_Thompson's avatar
Carl_Thompson
Regular Visitor
9 years ago
Solved

Relationships

Hi,   We have created a model and defined the relationships between tables.  When creating a visualisation in the report pane and capturing the SQL statement generated by Power BI within SQL Profil...
  • Carl_Thompson's avatar
    Carl_Thompson
    9 years ago

    Hi,

     

    With some help, we've bee able to determine why we were not seeing the behaviour we wanted. 

     

    As a Power Model is created as a Tabular Analysis Service in the back-end this model attempts to enforce INNER JOIN relationships between tables.  In our example we wanted to exhibit LEFT JOIN behaviour from our CRM table to our Task table.  A CRM record could have either no associated tasks, one associated task or multiple asociated tasks and we wanted to return all CRM records and the information of related tasks, if present.  However, when viewing the query passed back to the server, via SQL profiler, we could see that the first table referenced was the Task table with a LEFT OUTER join to the CRM table, which in essence, enforced an INNER JOIN relationship.

     

    In order to exhibit the LEFT JOIN behaviour we wanted there is a field option within the Report Pane of Power BI Desktop once you have dragged a field into the 'Values' section of the visualisation.  If you select the little dropdown arrow to the right of the field which has come from the table you want to left join TO (in our case the Task table), there is an otion of 'Show Items with No Data'.  

     

    With this option selected we then profiled the query passed back to the server and the query showed the first table to be the CRM table with a LEFT JOIN to the Task table, as required.

     

    So, the solution to our problem was unbelievably simple.  However, if you are unaware of this option or that this needs to be ticked in order to enforce LEFT JOIN behaviour then this could cause large issues in results.

     

    Hopefully,  this will help anyne who encounters a similar problem as we weren't able to find much help on the internet.  Maybe because it's so simple...

     

    Thanks,