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

We've captured the moments from FabCon & SQLCon that everyone is talking about, and we are bringing them to the community, live and on-demand. Starts on April 14th. Register now

Reply
River
Helper IV
Helper IV

Recursive query for a tree

Hi Friends,

 

We need to build a recursive query for our mangement hierarchy, and it's dynamic,  when given a node/person(not necessary the top person), we need to find out all subordinators under the person.

 

How can we achieve it?

 

Many thanks.

1 ACCEPTED SOLUTION
Anonymous
Not applicable

Hi @River ,

 

Try measure like

Measure = 
var _flag=IF(HASONEFILTER('Table'[Level 4]),4,IF(HASONEFILTER('Table'[Level 3]),3, IF(HASONEFILTER('Table'[Level 2]),2,IF(HASONEFILTER('Table'[Level 1]),1))))
var _v=UNION(VALUES('Table'[Level 1]),VALUES('Table'[Level 2]),VALUES('Table'[Level 3]),VALUES('Table'[Level 4]))
return IF(ISFILTERED('Table'),IF(MAX('Table 2'[Column])>_flag && MAX('Table 2'[Level 1]) in _v ,1,0)
)

13.png

 

 

Best Regards,

Stephen Tao

 

If this post helps, then please consider Accept it as the solution to help the other members find it more quickly.

 

View solution in original post

4 REPLIES 4
Anonymous
Not applicable

Hi @River ,

 

Try measure like

Measure = 
var _flag=IF(HASONEFILTER('Table'[Level 4]),4,IF(HASONEFILTER('Table'[Level 3]),3, IF(HASONEFILTER('Table'[Level 2]),2,IF(HASONEFILTER('Table'[Level 1]),1))))
var _v=UNION(VALUES('Table'[Level 1]),VALUES('Table'[Level 2]),VALUES('Table'[Level 3]),VALUES('Table'[Level 4]))
return IF(ISFILTERED('Table'),IF(MAX('Table 2'[Column])>_flag && MAX('Table 2'[Level 1]) in _v ,1,0)
)

13.png

 

 

Best Regards,

Stephen Tao

 

If this post helps, then please consider Accept it as the solution to help the other members find it more quickly.

 

mahoneypat
Microsoft Employee
Microsoft Employee

Please see this article on how to use the PATH function to generate the management chain for each employee.  You can then write DAX measures to dynamically show direct reports.

On the Right PATH() - A DAX/Power Query approach to working with parent/child hierarchies. | P3 Adap...

 

Pat

 





Did I answer your question? Mark my post as a solution! Kudos are also appreciated!

To learn more about Power BI, follow me on Twitter or subscribe on YouTube.


@mahoneypa HoosierBI on YouTube


Anonymous
Not applicable

Hi @River 

 

Can you provide some sample data? For hierarchy, you can probably use List.Generate in M or have a look at PATH in DAX

Hi Vera,

 

The hierarchy data is no different than any other company's management hierarchy. Can you provide a sample to do it?

 

Thanks,

Helpful resources

Announcements
New to Fabric survey Carousel

New to Fabric Survey

If you have recently started exploring Fabric, we'd love to hear how it's going. Your feedback can help with product improvements.

Power BI DataViz World Championships carousel

Power BI DataViz World Championships - June 2026

A new Power BI DataViz World Championship is coming this June! Don't miss out on submitting your entry.

Join our Fabric User Panel

Join our Fabric User Panel

Share feedback directly with Fabric product managers, participate in targeted research studies and influence the Fabric roadmap.