Power Query Problems

How to Calculate Employee Hierarchy Levels in Excel with Power Query

Amos GikundaAmos Gikunda Oct 22, 2026 874 views

Question details

The user needs a method to calculate multiple levels of management hierarchy for a large employee dataset using Power Query instead of basic worksheet formulas.

Calculate Employee Hierarchy Levels in Excel with Power Query
Product
Microsoft Excel
Device & OS
not provided
Scenario
Managing large organizational charts or employee lists (e.g., 23,000+ employees) where each record contains an Employee ID and a Supervisor ID.
Observed behavior
Repeated worksheet lookups like XLOOKUP or VLOOKUP become slow and difficult to maintain on massive datasets, whereas Power Query handles these merges more efficiently.
Before you start

Ensure your employee dataset is formatted as an official Excel Table and contains distinct, unique columns for Employee ID and Supervisor ID before importing it into Power Query.

Solution 1Recommended

Use Power Query Consecutive Merges

Perform sequential self-joins in Power Query to build the hierarchy level by level efficiently.

Power Query can solve hierarchy calculations by performing consecutive merges. Each step matches the current Supervisor ID with the corresponding Employee ID to retrieve the next supervisor up the chain.

1
Import Data to Power Query

Select your data table in Excel, navigate to the 'Data' tab, and click 'From Table/Range' to open the Power Query Editor.

2
Merge the Query with Itself

On the Home tab, click 'Merge Queries'. In the merge dialog, select the exact same query in the second dropdown to perform a self-join.

3
Match Supervisor to Employee ID

Select the 'Supervisor ID' column in the top table preview, and match it to the 'Employee ID' column in the bottom table preview, then click OK.

4
Expand the Next Level Supervisor

Click the expand icon at the top right of the newly merged column. Uncheck all columns except 'Supervisor ID', uncheck 'Use original column name as prefix', and rename the extracted column to 'Level 2 Supervisor'.

5
Repeat for Deeper Levels

Repeat the merge and expand process up to five times to calculate deeper hierarchy levels. Add a conditional column at the end to verify if the top-level supervisor has been reached (i.e., when the Supervisor ID is null).

Use Power Query Consecutive Merges
Performance Benefit: This method is highly scalable and remains easy to refresh and maintain, even for lists exceeding 20,000 employees.
Free Microsoft Office alternative

Edit and Analyze Large Datasets Seamlessly with WPS Office

If you are looking for a fast, lightweight, and completely free alternative to Microsoft Office, WPS Office offers powerful spreadsheet capabilities. It fully supports advanced formulas, large datasets, and seamless compatibility with Microsoft Excel formats.

  1. 1. Download and Install: Get WPS Office for free from the official website and run the quick installer.
  2. 2. Open Your Excel File: Launch WPS Spreadsheets and open your existing .xlsx employee dataset.
  3. 3. Calculate using Built-in Functions: Use WPS Spreadsheets' comprehensive function library to manage and analyze your hierarchy data effortlessly.
Fully compatible with Microsoft Excel formats (.xlsx, .xls, .csv).Supports advanced lookup functions like XLOOKUP and VLOOKUP for accurate hierarchy calculations.Lightweight architecture ensures smooth performance even with thousands of rows of employee data.Familiar user interface requiring no learning curve for former Excel users.
microsoft office alternative - wps office

Frequently Asked Questions

Why use Power Query over XLOOKUP for hierarchy mapping?

Power Query is optimized for large datasets. It processes data in the background, making your workbook lighter and preventing the lag associated with calculating thousands of live XLOOKUP formulas in real-time.

Can I calculate an unlimited number of hierarchy levels in Power Query?

While you can perform many consecutive merges, each merge requires a manual step in the Power Query editor. For exceptionally deep or variable hierarchies, advanced users often rely on custom M code or recursive logic functions instead of standard UI merges.

How do I update the hierarchy calculation if employee supervisors change?

Once your Power Query steps are saved and loaded to a worksheet, simply right-click the output table and select 'Refresh'. Power Query will automatically pull the updated source data and recalculate all hierarchy levels.