The ultimate Fabric, Power BI, SQL, and AI community-led learning event. Save €200 with code FABCOMM.
Get registeredEnhance your career with this limited time 50% discount on Fabric and Power BI exams. Ends September 15. Request your voucher.
Hi there,
I have a data set that shows each employee and the direct manager of that employee, and the manager's manager, similar to the below:
Employee | Line Manager | Line Manager +1 | Line Manager + 2 |
Fred | Mr Smith | Mr Jones | Mr Adams |
Tom | Mr Green | Mr Smith | Mr Red |
Joe | Mr Brown | Mr White | Mr Davis |
Not everyone in each column is all of the same seniority, it just shows the next level manager up for each employee. So for exampe if you worked for the most senior person the CIO for arguement sake, in Line Manager the name of the CIO would appear and subsequent columns "Line Manager +1" and "Line Manager +2" would be blank.
What i am trying to do with this data is to create columns that show the managers for each employee the manager they work for that sits at each level.
For example:
CIO | CIO + 1 | CIO + 2 | CIO + 3 |
Bob | Fred | Joe | Sara |
Bob | Fred | Joe | Greg |
Bob | Fred | Sam | Claire |
Bob | Tom | Richard | Kelly |
Bob | Tom | Paul | Liz |
Bob | Tom | James | Richard |
I am hoping i can get to this table by working just using the data that shows who each person's line manager is that i have detailed above.
In Power BI, you can achieve this transformation using Power Query (M language). Here's how to do it:
Load Your Data:
Prepare Your Data:
Create Custom Columns for Each Level of Management:
Here’s how you can do this step-by-step:
Open Power Query Editor:
Duplicate the Table:
Add Custom Columns:
CIO Column:
CIO +1 Column:
CIO +2 Column:
CIO +3 Column:
Here’s an example of how the M code might look for creating these custom columns:
Your final table should look like this:
Employee Line Manager Line Manager +1 Line Manager +2 CIO CIO + 1 CIO + 2 CIO + 3Fred | Mr Smith | Mr Jones | Mr Adams | Bob | Mr Smith | Mr Jones | Mr Adams |
Tom | Mr Green | Mr Smith | Mr Red | Bob | Mr Green | Mr Smith | Mr Red |
Joe | Mr Brown | Mr White | Mr Davis | Bob | Mr Brown | Mr White | Mr Davis |
This approach assumes the CIO is constant for all employees. If the CIO varies, you'll need to adjust the formula in the "CIO" column accordingly
User | Count |
---|---|
58 | |
56 | |
53 | |
49 | |
32 |
User | Count |
---|---|
172 | |
89 | |
70 | |
46 | |
45 |