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

The Power BI Data Visualization World Championships is back! Get ahead of the game and start preparing now! Learn more

Reply
eschultz
Regular Visitor

Creating Relationship Within the Same Table? Power Query

Hello,

 

I know there must be a formula or something I can use to create this relationship but not sure how. I have two tables that I have a relationship between. (Goal ID is the relationship key). When I filter on Goal 23, Animal ID 46 does not come through because it does not have a Goal ID. However, you can see that the parent ID is 45. So through this hierarchy , the Goal ID should be 23. Can someone help me create this relationship? Is it a formula or some type of table I need to create? Thank you!

 

Goal IDGoal
23Increase Speed

 

Animal ID

Animal

Animal TierGoal IDParent Animal  

45

Dog

Adult23   
46PuppyBaby 45  
2 ACCEPTED SOLUTIONS
serpiva64
Solution Sage
Solution Sage

Hi, you can obtain this result

serpiva64_0-1677316388514.png

by merging on itself you table

serpiva64_1-1677316446462.png

and then expanding 

serpiva64_2-1677316480284.png

and sorting

serpiva64_3-1677316515726.png

here is the example

let
Source = Table.FromRows(Json.Document(Binary.Decompress(Binary.FromText("i45WMjFV0lFyyU8Hko4ppTklQNrIGEgoxeoAJc2ArIDSgoJKIO2UmASigAioJzYWAA==", BinaryEncoding.Base64), Compression.Deflate)), let _t = ((type nullable text) meta [Serialized.Text = true]) in type table [AnimalID = _t, Animal = _t, AT = _t, GoalId = _t, #"Parent Animal" = _t]),
#"Merged Queries" = Table.NestedJoin(Source, {"Parent Animal"}, Source, {"AnimalID"}, "Source", JoinKind.LeftOuter),
#"Expanded Source" = Table.ExpandTableColumn(#"Merged Queries", "Source", {"GoalId"}, {"GoalId.1"}),
#"Sorted Rows" = Table.Sort(#"Expanded Source",{{"AnimalID", Order.Ascending}})
in
#"Sorted Rows"

 

If this post is useful to help you to solve your issue, consider giving the post a thumbs up and accepting it as a solution!

 

 

 

 

View solution in original post

Thank you!! So helpful

View solution in original post

2 REPLIES 2
serpiva64
Solution Sage
Solution Sage

Hi, you can obtain this result

serpiva64_0-1677316388514.png

by merging on itself you table

serpiva64_1-1677316446462.png

and then expanding 

serpiva64_2-1677316480284.png

and sorting

serpiva64_3-1677316515726.png

here is the example

let
Source = Table.FromRows(Json.Document(Binary.Decompress(Binary.FromText("i45WMjFV0lFyyU8Hko4ppTklQNrIGEgoxeoAJc2ArIDSgoJKIO2UmASigAioJzYWAA==", BinaryEncoding.Base64), Compression.Deflate)), let _t = ((type nullable text) meta [Serialized.Text = true]) in type table [AnimalID = _t, Animal = _t, AT = _t, GoalId = _t, #"Parent Animal" = _t]),
#"Merged Queries" = Table.NestedJoin(Source, {"Parent Animal"}, Source, {"AnimalID"}, "Source", JoinKind.LeftOuter),
#"Expanded Source" = Table.ExpandTableColumn(#"Merged Queries", "Source", {"GoalId"}, {"GoalId.1"}),
#"Sorted Rows" = Table.Sort(#"Expanded Source",{{"AnimalID", Order.Ascending}})
in
#"Sorted Rows"

 

If this post is useful to help you to solve your issue, consider giving the post a thumbs up and accepting it as a solution!

 

 

 

 

Thank you!! So helpful

Helpful resources

Announcements
Power BI DataViz World Championships

Power BI Dataviz World Championships

The Power BI Data Visualization World Championships is back! Get ahead of the game and start preparing now!

December 2025 Power BI Update Carousel

Power BI Monthly Update - December 2025

Check out the December 2025 Power BI Holiday Recap!

FabCon Atlanta 2026 carousel

FabCon Atlanta 2026

Join us at FabCon Atlanta, March 16-20, for the ultimate Fabric, Power BI, AI and SQL community-led event. Save $200 with code FABCOMM.