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

Compete to become Power BI Data Viz World Champion! First round ends August 18th. Get started.

Reply
sglendenning
Helper II
Helper II

Parent Child Hierarchy In Large Data Set

I have a data set where only the original parent has a data field entry (in the example below it is Company) that I want to get to when looking at the child.  The Company is only filled out on the first entry and will be blank for the child entries.  I would like to get to a couple different views; 

  1. What is the original Parent number and Company.
  2. What is the original Parent and all Childer leading to most recent child.
  3. Bring in the original parent company to all children

I have 300K rows of data and a parent could have dozens of children.

 

ParentChildNameTypeCompany
111111 JohnNewApple
222222111111JohnRed 
8675309222222JohnYellow 
999999998675309JohnRed 
5 REPLIES 5
ziying35
Impactful Individual
Impactful Individual

Hi, @sglendenning 

Such a problem can be solved by writing recursive code, but I haven't used it on that large amount of data. Can you simulate more amount of data and the effect you want to achieve and upload this file to the cloud drive and share the link here? Because @edhans  and I are equally unable to figure out what you expect to achieve

edhans
Super User
Super User

I'm not sure exactly what you want. Can you give us expected output for this? I know Company needs to be filled out, and that is easy. Just right-click on the Company field and select Fill Down.

edhans_1-1598573258505.png

 

becomes 

edhans_3-1598573394917.png

Those cells have to be null, not blank. If they are blank without the word null in them, then first go to Transform, Replace Values, and leave the first field blank, put null in the second. Then do the fill down.

 

 

edhans_2-1598573376343.png

To help with the rest, I'd need a screen shot or a clearer understanding of the end goal.

 

 



Did I answer your question? Mark my post as a solution!
Did my answers help arrive at a solution? Give it a kudos by clicking the Thumbs Up!

DAX is for Analysis. Power Query is for Data Modeling


Proud to be a Super User!

MCSA: BI Reporting

My most critical output would be to get the Company from the original Parent to be filled in for all the children.  In my data the Parent becomes the child on the next purchase by the same customer and continues in this fashion until we come to present day.  There is no relationship between the Parent ID's within the field...it is essentially a number ID of the next sale of a product so I can't sort by either Parent nor Child and use a Fill Down function.  A recursive operation sounds like it would work to search the Child ID back through all the Parent ID's until a Parent ID with a Company name is found, but I have no idea how to pull that off.  I will try to pull together a data set that is representative of what I have and what I am after.

Anonymous
Not applicable

pending further information to develop and make the code efficient according to the data structure, I propose this idea:

a function:

 

let
    
    genealogy=(adamo) =>
        let 
        Co=ct[Company]{adamo},
         g=   List.Generate(
        ()=>[Par=ct[Parent]{r},Ch=ct[Child]{r},Last=true,r=adamo],
        each [Last],
        each [r=List.PositionOf(ct[Child],ct[Parent]{[r]}), Par=ct[Parent]{r},Ch=ct[Child]{r},Last=Logical.From(1+r)],

        each ct{[r]}&[Company=Co]
    )
in Table.FromRecords(g)
in
    genealogy

 

 

that receive a seed in input  and give a table out output:

 

immagine.png

 

if you invoke with seed 0

immagine.png

 

if you invoke with seed 4

 

immagine.png

 

There is, of course, a lot to improve in search expressions, but it can be done specifically once you know the structure of the data and also the expected result.

 

 

 

 

 

Anonymous
Not applicable

or somethink like this:

 

 

let

   genealogy=(adamo) =>
        let 
        Co=ct[Company]{adamo},
         g=   List.Generate(
        ()=>[Par=ct[Parent]{r},Ch=ct[Child]{r},Last=true,r=adamo],
        each [Last],
        each [r=List.PositionOf(ct[Child],ct[Parent]{[r]}), Par=ct[Parent]{r},Ch=ct[Child]{r},Last=Logical.From(1+r)],

        each [Par]
    )
in  ct{adamo}&[Parent=Text.Combine(g,", "), Child=Text.Combine({"null"}&List.RemoveLastN(g,1),", ")],

    Source = Table.AddIndexColumn(ct,"idx",0,1),
    seeds = Table.SelectRows(Source, each ([Child] = ""))[idx],
    recs=List.Transform(seeds,each genealogy(_))

in
    Table.FromRecords(recs)

 

 

which, when invoked against this table:

 

immagine.png

 

gives  this table :

 

immagine.png

 

 

 

Helpful resources

Announcements
July 2025 community update carousel

Fabric Community Update - July 2025

Find out what's new and trending in the Fabric community.

July PBI25 Carousel

Power BI Monthly Update - July 2025

Check out the July 2025 Power BI update to learn about new features.

Top Solution Authors