Forum Discussion
Parent-Child Hierarchy - Highest Parent (using Power Query not DAX)
- 7 years ago
you just need to change the data types then like this:
let Source = Excel.CurrentWorkbook(){[Name="Hierarchy"]}[Content], ChangedType = Table.TransformColumnTypes(Source,{{"Team ID", type text}, {"Parent ID", type text}}), ListTeamID = List.Buffer( ChangedType[Team ID] ), ListParentID = List.Buffer( ChangedType[Parent ID] ), fnGetHighestParent = (n as text) as text => let PosOfParent = List.PositionOf( ListTeamID, n ), ParID = ListParentID{PosOfParent} in if ParID = null then ListTeamID{PosOfParent} else @fnGetHighestParent(ListParentID{PosOfParent}), FinalTable = Table.AddColumn( ChangedType, "HighestParent", each fnGetHighestParent( [Team ID] ), type text) in FinalTable
LivioLanzo sorry I should have mentioned I was referring to the problem in the solution as proposed by PattemManohar.
LivioLanzo I will test your solution and get back to you.
Hi LivioLanzo so your query does not work because I believe you are checking the numbers for the smallest number whereas in fact my team names are not really numbers but as follows
Team ID - Parent ID - Higest Parent
B1 - null - B1 (because it is null)
B2 - null - B2 (because it is null)
T1 - B1 - B1
T2 - T1 - B1
T3 - B2 - B2
T4 - T3 - B2
Removing the B or the T is also not a solution as there is a B1 and a T1, we need to climb up the hierarchy
Thanks,
Moiz
- LivioLanzo7 years ago
Solution Sage
you just need to change the data types then like this:
let Source = Excel.CurrentWorkbook(){[Name="Hierarchy"]}[Content], ChangedType = Table.TransformColumnTypes(Source,{{"Team ID", type text}, {"Parent ID", type text}}), ListTeamID = List.Buffer( ChangedType[Team ID] ), ListParentID = List.Buffer( ChangedType[Parent ID] ), fnGetHighestParent = (n as text) as text => let PosOfParent = List.PositionOf( ListTeamID, n ), ParID = ListParentID{PosOfParent} in if ParID = null then ListTeamID{PosOfParent} else @fnGetHighestParent(ListParentID{PosOfParent}), FinalTable = Table.AddColumn( ChangedType, "HighestParent", each fnGetHighestParent( [Team ID] ), type text) in FinalTable- moizsherwani7 years ago
Continued Contributor
- moizsherwani7 years ago
Continued Contributor
- msksenthil4 years ago
Helper III
Thanks to moizsherwani and LivioLanzo
But when we using the same for larger dataset like 32k rows it shows the below error
- iBusinessBI3 years ago
Kudo Collector
LivioLanzo Awesome, thank you!