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

Register now to learn Fabric in free live sessions led by the best Microsoft experts. From Apr 16 to May 9, in English and Spanish.

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
Microsoft Fabric Learn Together

Microsoft Fabric Learn Together

Covering the world! 9:00-10:30 AM Sydney, 4:00-5:30 PM CET (Paris/Berlin), 7:00-8:30 PM Mexico City

PBI_APRIL_CAROUSEL1

Power BI Monthly Update - April 2024

Check out the April 2024 Power BI update to learn about new features.

April Fabric Community Update

Fabric Community Update - April 2024

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