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
PauloH
Frequent Visitor

Span of Control

Hi all,

 

I have a table structured like this:

 

EmployeeManager
1 
21
31
41
52
62
72
82
92
103
113
123
133
144
154

 

I'm trying to implement a calculated column for Span of Control, basically count the number of occurances on Employee in the Manager column, like this:

EmployeeManagerSpan of Control
1 3
213
314
410
520
620
722
870
970
1030
1130
1232
13120
14120
1530

 

In Excel, formula goes like COUNTIF(Manager Range, Employee), quite easy, however, no DAX formula variations I've tried (COUNTX, CALCULATE) has yielded the result I need. Any idea? 

1 ACCEPTED SOLUTION
Smauro
Solution Sage
Solution Sage

You could simply add a new column with DAX:

 

Span of Control =
VAR x = [Employee]
RETURN
    CALCULATE ( COUNTROWS ( 'Table' ), FILTER ( 'Table', x = [Manager] ) )

You should change the 'Table' with your table name.

Edit: You may add a " + 0" after the "COUNTROWS(TABLE)" in order to not display null results




Feel free to connect with me:
LinkedIn

View solution in original post

11 REPLIES 11
Smauro
Solution Sage
Solution Sage

You could simply add a new column with DAX:

 

Span of Control =
VAR x = [Employee]
RETURN
    CALCULATE ( COUNTROWS ( 'Table' ), FILTER ( 'Table', x = [Manager] ) )

You should change the 'Table' with your table name.

Edit: You may add a " + 0" after the "COUNTROWS(TABLE)" in order to not display null results




Feel free to connect with me:
LinkedIn

I was battling with this same issue and this worked for me as well!  Thank you!!!

Assuming your employees don't repeat, @Smauro gave a better solution than I did. Kudos to him.

@wwhittenton you are right, thank you!
I took it for certain that the employees would be unique.. If not, then your solution works better.




Feel free to connect with me:
LinkedIn

@Smauro In retrospect, that's the better (or perhaps only viable) assumption. If the employees are not unique, the span of control calculation comes out incorrect either way, because the manager an individual reports to would be double-counted even in the new table.

 

Thanks for the good wishes and happy holidays to you and to you as well, @PauloH.

@wwhittenton I think you're right. And there may be some people with more than one manager as well.
@PauloH So, in case your Employee-Manager has duplicates, you should first go on Query Editor, Select both Employee and Manager columns and right click-> remove duplicates. And then, add the column I mentioned.

 

Happy holidays to you too @wwhittenton! And @PauloH 🙂




Feel free to connect with me:
LinkedIn

PauloH
Frequent Visitor

Hi @Smauro, any idea of how could this work in case there're duplicates? i.e. having different snapshot periods (months), hence getting some duplicates in the Employee and Manager column.

Hi @PauloH,

 

Since you said you have snapshots, I'm assuming you want the most recent manager for a given employee (they could change over time). I built that into the calculation. This will require a new table, achieved by going to the Modeling tab and selecting "New Table". Then, use the following:

Span of Control = SUMMARIZE( Sheet1 , Sheet1[employee] , 
"Date" , MAX(Sheet1[Date]) ,
"manager" , calculate(max(Sheet1[manager]),
FILTER(Sheet1 , Sheet1[Date] = MAX(Sheet1[Date]))))

This will return a distinct list of employees with their respective manager for the most recent time period. Once that's done, you can follow the code you used originally in an additional column:

SpanOfControl = 
var x = 'Span of Control'[employee]
return
CALCULATE( COUNTROWS('Span of Control') , FILTER( 'Span of Control', x = 'Span of Control'[manager] ))

I hope this helps!

 

Best,

Will

 

 

 

 

Hi @wwhittenton, it could be a bit more complicated, as users should be able to filter by dates. I'll use below as input and see how I can make it work. Thanks! 

PauloH
Frequent Visitor

Thanks, all! Just tested the solution and it seems to work exactly as I intended! Happy Holidays!

wwhittenton
Helper II
Helper II

Hi @PauloH,

 

This may not be exactly the way you wanted to do it, but it should work.

 

Create a New Table by clicking on the "New Table" button in the Calculations section of the Home tab. then use the formula

Employee = DISTINCT(Data[employee])

 

 After that, create a New Column and use the following:

Span_of_Control = CALCULATE( COUNT(Data[manager]) , FILTER(Data , Employee[employee] = Data[Manager] ))

Remember to change the table / column names as needed. If you need to use filters or slicers in your data display, you'll be able to create a One-to-Many or Many-to-Many relationship to make them work correctly.

 

Hope this helps!

Will

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.