Quantcast
Channel: Power Query Archives –
Viewing all articles
Browse latest Browse all 111

Parent-Child Hierarchies with multiple parents in Power BI with Power Query

$
0
0

I’ve written about a method to dynamically flatten parent-child-hierarchies also with multiple parents some while ago here. I’ve actually used this approach for Bill-of-materials cases and refined that approach in a series starting here. There, the quantities are aggregated in M already, as they are not supposed to change. But if one wants to use the hierarchical structure to report on transaction tables where several filters shall be applied, one has to adjust the data model a bit:

DimNodes

If you have parent-child-hierarchy with multiple parents, my function will a table like below, where the children with multiple parents still reside in different rows:

Due to this, the table cannot directly be connected with the FactTable, as NodeKey is not unique. Solution is to create DimNode-table that contains only unique values from the NodeKeys. Use it as a bridge between the 2 tables and implement a bidirectional filter to the Nodes-table:

Best to hide that table from view, because the fields for the matrix visual have to come from the original tables. Now look at this:

Doesn’t that look like the perfect ragged parent-child-hierarchy-matrix?

Of course, the totals won’t add up, but that’s by design if you allocate items to multiple parents.

All measures are taken from the Russo/Ferrari Parent-Child-Pattern. My M-function produces the same structure than the table created by DAX-functions in that article. Just that it does it dynamically, so you don’t have to add new levels manually and copes with multiple parents. Sure, the dynamic aspect is useless, if you want to create a traditional hierarchy like described in this post, but for Bill-of-materials-solutions, where you aggregate the values in Power Query already, that’s pretty useful actually.

File to download:  Parent Child Hierarchy Multiple Parents

Enjoy and stay queryious 😉

Note: The code of the M-function is fairly old an quite embarrassing, but as it works, an update doesn’t get a high priority currently 😉

The post Parent-Child Hierarchies with multiple parents in Power BI with Power Query appeared first on The BIccountant.


Viewing all articles
Browse latest Browse all 111

Trending Articles