Solved: Create a hierarchy in PB Desktop from a self refer - Microsoft Power BI Community
Simple Example of a Many to Many (M2M) Relationship Problem. First, many-to-many and self-referencing (parent-child) relationships are not For example, in the Power Pivot window three relationships exist, but two are. entity relationship designer, PowerPivot, Error List pane, AMO, tables attribute relationships, dimensions, , fact table, self-referential table.
Sometimes the requirement of many-to-many relationship can be satisfied through cross filters that persist a filter context across multiple table relationships. Self-joins and loops Self-joins are not permitted in tabular model tables. A self-join is a recursive relationship between a table and itself.
Self-joins are often used to define parent-child hierarchies. For example, you could join an Employees table to itself to produce a hierarchy that shows the management chain at a business.
The model designer does not allow loops to be created among relationships in a model.
In other words, the following set of relationships is prohibited. Table 1, column a to Table 2, column f Table 2, column f to Table 3, column n Table 3, column n to Table 1, column a If you try to create a relationship that would result in a loop being created, an error is generated. Inference of relationships In some cases, relationships between tables are automatically chained.
For example, if you create a relationship between the first two sets of tables below, a relationship is inferred to exist between the other two tables, and a relationship is automatically established. Products and Category -- created manually Category and SubCategory -- created manually Products and SubCategory -- relationship is inferred In order for relationships to be automatically chained, the relationships must go in one direction, as shown above.
If the initial relationships were between, for example, Sales and Products, and Sales and Customers, a relationship is not inferred. This is because the relationship between Products and Customers is a many-to-many relationship. Detection of relationships when importing data When you import from a relational data source table, the Table Import Wizard detects existing relationships in those source tables based on the source schema data.
Self Referencing Tables in Power Query - Excelerator BI
If related tables are imported, those relationships will be duplicated in the model. Manually create relationships While most relationships between tables in a single relational data source will be detected automatically, and created in the tabular model, there are also many instances where you must manually create relationships between model tables.
If your model contains data from multiple sources, you will likely have to manually create relationships.
For example, you may import Customers, CustomerDiscounts, and Orders tables from a relational data source. Relationships existing between those tables at the source are automatically created in the model.
You may then add another table from a different source, for example, you import region data from a Geography table in a Microsoft Excel workbook. You can then manually create a relationship between a column in the Customers table and a column in the Geography table.
- Relationships between tables in a Data Model
- Create a hierarchy in PB Desktop from a self referencing table
- Types of Relationships
To manually create relationships in a tabular model, you can use the model designer in Diagram View or by using the Manage Relationships dialog box. The diagram view displays tables, with relationships between them, in a graphical format.
You can click a column in one table and drag the cursor to another table to easily create a relationship, in the correct order, between the tables. The Manage Relationships dialog box displays relationships between tables in a simple table format.
Duplicate values and other errors If you choose a column that cannot be used in the relationship, a red X appears next to the column. You can pause the cursor over the error icon to view a message that provides more information about the problem. Problems that can make it impossible to create a relationship between the selected columns include the following: Problem or message Resolution The relationship cannot be created because both columns selected contain duplicate values.
To create a valid relationship, at least one column of the pair that you select must contain only unique values. You can either edit the columns to remove duplicates, or you can reverse the order of the columns so that the column that contains the unique values is used as the Related Lookup Column.
The column contains a null or empty value. If the sort order of the source table changes and then you refresh the query, the comments no longer align with the original data. And this is despite having a unique ID column in the original table. Enter Self Referencing Tables I read this blog post from Imke quite some time ago, and that was what gave me the idea on how I could solve this problem.
Create and manage relationships in Power BI Desktop
The idea is to load table 2 above a second time after adding the commentsand then joining it back to itself, hence logically joining the manually added comments to the rows in the main table. This was my starting point. Then I loaded the resulting table 2 a second time as follows: The next thing to do is to merge the original query with the new query.
This will give you a new column in your query, and the column contains a table as shown below. You can then expand this new column to extract the comments. I only extracted the comments column, and deselected the last option as shown below. Click OK, then close and load.
When you look at the table now, it all looks the same as before see belowbut there is one important difference. The last column in the Power Query Table is now a part of the table and not a manually added on column. You now have a self referencing table.