Forum Discussion
Hanuma_Srikiran
8 years agoFrequent Visitor
Comparing Two columns with Output (Parent and Child relation)
Hi , I have a source file like below Child Parent Parrot Pet LoveBirds Pet Eagle Adventures Bat Adventures Lion Wild Tiger Wild Cow Domestic Goat Domestic Wha...
- 8 years ago
Try this Calculated Table.
New Table = VAR AllParent = SELECTCOLUMNS ( TableName, "AllParents", TableName[Parent] ) VAR Firstparent = ADDCOLUMNS ( EXCEPT ( ALL ( TableName[Child] ), ALL ( TableName[Parent] ) ), "FirstParent", CALCULATE ( VALUES ( TableName[Parent] ) ) ) VAR secondparent = ADDCOLUMNS ( SELECTCOLUMNS ( Firstparent, "LastChild", [Child], "FirstParent", [FirstParent] ), "SecondParent", LOOKUPVALUE ( TableName[Parent], TableName[Child], [FirstParent] ) ) VAR thirdparent = ADDCOLUMNS ( SUMMARIZE ( secondparent, [LastChild], [FirstParent], [SecondParent] ), "ThirdParent", LOOKUPVALUE ( TableName[Parent], TableName[Child], [SecondParent] ) ) VAR Fourthparent = ADDCOLUMNS ( SUMMARIZE ( thirdparent, [LastChild], [FirstParent], [SecondParent], [ThirdParent] ), "FourthParent", LOOKUPVALUE ( TableName[Parent], TableName[Child], [ThirdParent] ) ) RETURN FILTER ( UNION ( SUMMARIZE ( Fourthparent, [LastChild], [FirstParent] ), SUMMARIZE ( Fourthparent, [LastChild], [SecondParent] ), SUMMARIZE ( Fourthparent, [LastChild], [ThirdParent] ), SUMMARIZE ( Fourthparent, [LastChild], [FourthParent] ) ), [FirstParent] <> BLANK () )
Zubair_Muhammad
8 years agoCommunity Champion
I think it would be easy.
You would have to add 5th parent and so on in the same pattern as 3rd and 4th parent ....inside the "VAR"
And then add it to the Union Query.
If it doesn't work, please copy paste your full data here (or provide the file).... I will try to fix it
Hanuma_Srikiran
8 years agoFrequent Visitor
Yeah, it's easy by hard coding the dax.
But I want it to be dynamic with respect to the number of Parents, without hardcoding the DAX.
- Zubair_Muhammad8 years agoCommunity Champion
I believe this requires a recursive operation which is not supported in DAX....
But there might be a solution in Power Query....