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

Join us for an expert-led overview of the tools and concepts you'll need to become a Certified Power BI Data Analyst and pass exam PL-300. Register now.

Reply
DmitryKo
Helper IV
Helper IV

Recursive relationships

Let's say we have a simple table for entities and their IDs (TableA) and another table that defines relationships in a format similar to this:

 

IncomingIDOutgoingID<some attributes that are irrelevant>
12 
23 
24 
56 
57 

 

We need to be able to find all entities related to any given "starting" ID; in the sample data above, for ID=1, we would expect {2, 3, 4} as the correct set, as 2 is related to 1 and then both 3 and 4 are related to 2. Relationship defined that way can be recursive.

 

What is the correct approach to configure this as a part of the model and what kind of DAX code can be used to achieve the sample scenario?

 

3 REPLIES 3
DmitryKo
Helper IV
Helper IV

The relationship is a conceptual "many to many". A given item could have more than one "parent" - any pair of item1 and item2 could have from 0 to n relationships (of different type), where n is 1 or higher.

 

Also there could be just 1 level of nesting or 4-6 levels of nesting, depending on specific dataset. Would approach with PATH cover it?

Hi, 
I have tested this as follows:

scee07_0-1700120355945.png

The calculated column uses the PATH function. The error explcitely says that a child with multiple parents is not supported. 

With a "clean" tree it works:

scee07_1-1700120508053.png

 

The big question is what you explicitely know about your graph in advance. If you only have an adjacency matrix or list you are condemmed to graph exploration algorithms. A lot of patterns cover cases, where you know the depth of the graph and can explicitely model what you want.  I asked a similar question to the community some time ago, where I gave my aproach in order to ask if they are easier ways: 

Multiparent Graph, Recursiveness - Microsoft Fabric Community

I got no answer as the text was presumably too long to read 🙂

 

Best regards 

 

Christian

 

scee07
Resolver I
Resolver I

Hi, 

if this is a simple tree (every child has exactly one parent, and there are no cycles), then you can use PATH (https://learn.microsoft.com/en-us/dax/path-function-dax). If this hasn't changed, general graph structured are not covered by PATH.
If this is case, I would cross join all nodes and return the path from path. 

If this is not the case, I reverted back to Power Query as Power Query is recursive and DAX is not. There you can implement graph search algorithms like DFS, BFS and then import the result to Power BI, ...

 

Best regards 

 

Christian

 

Helpful resources

Announcements
Join our Fabric User Panel

Join our Fabric User Panel

This is your chance to engage directly with the engineering team behind Fabric and Power BI. Share your experiences and shape the future.

June 2025 Power BI Update Carousel

Power BI Monthly Update - June 2025

Check out the June 2025 Power BI update to learn about new features.

June 2025 community update carousel

Fabric Community Update - June 2025

Find out what's new and trending in the Fabric community.