Forum Discussion
moizsherwani
Continued Contributor
7 years agoParent-Child Hierarchy - Highest Parent (using Power Query not DAX)
Hello PBI Forum, So my issue is as follow, I have a parent child relationship as given below and I need (within Power Query and not DAX) a way to find out the highest parent of any child Team...
- 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
moizsherwani
Continued Contributor
7 years agomoizsherwani
Continued Contributor
7 years agoLivioLanzo I managed to fix that error but get an error on the final step now saying
"Expression.Error: We cannot convert a value of type List to type Table.
Details:
Value=List
Type=Type"
- LivioLanzo7 years ago
Solution Sage
moizsherwani Are you pasting the code exactly as it is? If not, what is the complete M code?
- moizsherwani7 years ago
Continued Contributor
LivioLanzo I realized I was making a mistake with the code. The solution works perfectly. Thanks so much.