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
Anonymous
Not applicable

nested filter counting the rows with a condition

Hi I need to build a DAX measure to know how many people reporting to a person, in a typical Org structure.

My org data table has all employees with along with thier team lead, manager and director as separate columns.

If the person is a manager, there is no team lead for him. But there is a director on the top. 

I need to know how many people under each person. See sample data in below pic

 

I spend enough time, trying with filters/count, its not taking me anywhere. Greatly appreciate your help. 

 

org3.jpg

 

 

 

 

 

1 ACCEPTED SOLUTION
Anonymous
Not applicable

I was able to make it work with below script

 

Team Count = 
var currentName = Sheet1[Employee Name]

var cnt = 
SWITCH(Sheet1[Position],
            "TL",
                    calculate(
                            COUNT(Sheet1[Employee Name]),
                            FILTER(Sheet1, Sheet1[Team Lead]=currentName)
                    ),
            "M",
                    calculate(
                            COUNT(Sheet1[Employee Name]),
                            FILTER(Sheet1, Sheet1[Manager]=currentName)
                    ),
            "D",
                    calculate(
                            COUNT(Sheet1[Employee Name]),
                            FILTER(Sheet1, Sheet1[Director]=currentName)
                    ),
            0
)
return cnt

 solution.jpg

 

View solution in original post

1 REPLY 1
Anonymous
Not applicable

I was able to make it work with below script

 

Team Count = 
var currentName = Sheet1[Employee Name]

var cnt = 
SWITCH(Sheet1[Position],
            "TL",
                    calculate(
                            COUNT(Sheet1[Employee Name]),
                            FILTER(Sheet1, Sheet1[Team Lead]=currentName)
                    ),
            "M",
                    calculate(
                            COUNT(Sheet1[Employee Name]),
                            FILTER(Sheet1, Sheet1[Manager]=currentName)
                    ),
            "D",
                    calculate(
                            COUNT(Sheet1[Employee Name]),
                            FILTER(Sheet1, Sheet1[Director]=currentName)
                    ),
            0
)
return cnt

 solution.jpg

 

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.