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

Grow your Fabric skills and prepare for the DP-600 certification exam by completing the latest Microsoft Fabric challenge.

Reply
iBusinessBI
Kudo Collector
Kudo Collector

Power Query - flatten Parent-child hierarchy

I have a parent-child hierarchy table. I don't know in advance how many levels there are.

I need help with building a function that would flatten the levels.

I found this very helpful post:

https://pivotalbi.com/dynamically-flatten-a-parent-child-hierarchy-using-power-query-m/

It does everything. But it leaves "low" levels empty if the hierarchy is not longest.

So I basically ask for your help altering some M code to fill the empty values with the values from level above.

iBusinessBI_0-1684517158015.png

Here is a Power BI file

https://1drv.ms/u/s!AoP_9ampPIT7gdFtb4M-04m-1Z6JgQ?e=9EIk25

Thanks

1 ACCEPTED SOLUTION

3 REPLIES 3
ChandanaMB13
Regular Visitor

Hey how do you integrate/ define relationship between actual table data and this data in the bi visuals. 

I had a data table which had parentid and childid, I used this and created the levels and added it to slicer now I want my visual to show me data related to only the selected childid or group id.Any idea on this

lbendlin
Super User
Super User

You are not just flattening the hierarchy - you are also forcibly converting it from ragged to fixed depth.  Doing that with repetitions of values is generally frowned upon. While the function you mentioned could be modified that would include a second run to identify the maximum level of depth before you would then traverse the hierarchy.  I don't think it is a good idea.  What's the next step?  

 

Note that Power Query producing variable output is asking for trouble.  Your downstream processes (Power BI Meta data) will break.

I've solved it with a help of @LivioLanzo  solution to this post.
https://community.powerbi.com/t5/Desktop/Parent-Child-Hierarchy-Highest-Parent-using-Power-Query-not...

It's dynamic, not fixed solution.

Helpful resources

Announcements
RTI Forums Carousel3

New forum boards available in Real-Time Intelligence.

Ask questions in Eventhouse and KQL, Eventstream, and Reflex.

MayPowerBICarousel1

Power BI Monthly Update - May 2024

Check out the May 2024 Power BI update to learn about new features.