Forum Discussion

Anonymous's avatar
Anonymous
Not applicable
3 years ago
Solved

How do I make this loop all children recursively?

Hello guys,    i have a function ("flecheD") (ColChild,ColParent,ParentActuel,source)=> let mylist=Table.Column(Table.SelectRows(source,each Record.Field(_,C...
  • ppm1's avatar
    3 years ago

    Please try this function. Seems to be do what you are looking for.

     

    (inputtable as table, searchvalue as text, inputtext as text)=>
    let 
    input = searchvalue,
    childrows = try Table.SelectRows(inputtable, each [Parent] = input)[Child] otherwise {},
    output = if List.IsEmpty(childrows) then inputtext & Text.Combine(childrows, "") else Text.Combine(childrows, "") & Text.Combine(List.Transform(childrows, each @fnParentChild(inputtable, _, "")), "|")
    in 
    output

     

    If needed, you can see it with your data, you can put this in a blank query.

    let
        Source = Table.FromRows(Json.Document(Binary.Decompress(Binary.FromText("i45WclTSUXIC4oAgfxcQ08s5VClWJ1rJGchxQYi71HiChUHKvbAo98Kt3BmLcpB4KBZxEMcTIQ40JBYA", BinaryEncoding.Base64), Compression.Deflate)), let _t = ((type nullable text) meta [Serialized.Text = true]) in type table [Parent = _t, Child = _t, Param = _t, Children = _t]),
        #"Changed Type" = Table.TransformColumnTypes(Source,{{"Parent", type text}, {"Child", type text}, {"Param", type text}, {"Children", type text}}),
        #"Added Custom" = Table.AddColumn(#"Changed Type", "Custom", each let par = [Parent] in fnParentChild(#"Changed Type", par, ""))
    in
        #"Added Custom"

    Pat