Formula to create a hierarchy for a list of employees

zinah

Active Member
Joined
Nov 28, 2018
Messages
368
Office Version
  1. 365
Platform
  1. Windows
Hi,

I have below list of employees along with their managers and what I need is to create hierarchy for each employee (row). Can anyone recommend a formula that serve my purpose?

create a hierarchy.xlsx
ABCDEFGH
1EE IDManager IDManagement Level 1Management Level 2Management Level 3Management Level 4Management Level 5Management Level 6
21006016920020704
31017883211535541
41063840250000503
51065248511595721
61065348520017465
71067323150000155
81071943620016537
91071993911545563
101086211150000153
111109067850000254
121111590511589682
131114904611588799
141122457250001103
151126231811535541
161142815720011901
171148347620017024
181149718710060169
191150685120020242
201150847011545638
211151268411497187
221151290111497187
231151333011497187
241151344611741241
251151498611611806
261152020320016654
271153554111540468
281153555311543214
291153556520016640
301153581211545563
311153581411543214
321153714611739111
331153739910060169
341153845020019675
351153852711595031
361153856611595213
371153859020009235
381153859211542391
391153860110653485
401153860420020218
411153861111548384
421153862820019410
431153863111540682
441153864511545630
451153865050001383
461153865211751231
471153865311541921
481153866720007059
491153866820008210
501153869750001584
511153871711542168
521153873211595210
531153873611595319
541153874111542044
551153874311595213
561153878720016698
571153879711595213
581153880911595213
591153881320016291
601153885820016947
611153886811595307
621153887211543214
631153889211540810
641153892611594879
651153894311543855
661153896320013089
671153896750000935
681153897011595008
691153897911688035
701153898411581442
711153898950002237
721153900111540702
731153901450001584
741153906111540665
751153908120016882
761153909611557496
771153909811595213
781153916811595209
791153918511544247
801153919211541947
811153920011542524
821153920320017465
831153978320020450
841153978411602773
851153979050000152
861153979311628642
871153979450001200
881153979811595307
891154025811539001
901154026220007077
911154026311540606
921154028920013248
931154029211542397
941154032711544140
951154034111545360
961154034920006166
971154039411595057
981154040820011856
991154041820006793
1001154042811540584
1011154044111542352
1021154044211540468
1031154045020016605
1041154046850000252
1051154047020005830
1061154050120013248
1071154051850000005
1081154054111544247
1091154056311540341
1101154058320017691
1111154058420000086
1121154058511541977
1131154060611540618
1141154061520016803
1151154061811538813
1161154062520016947
1171154063250001656
1181154064211594944
1191154064611542504
1201154065111595213
1211154065520000086
Sheet3
 

Excel Facts

Which lookup functions find a value equal or greater than the lookup value?
MATCH uses -1 to find larger value (lookup table must be sorted ZA). XLOOKUP uses 1 to find values greater and does not need to be sorted.
If I understood well, such a formula copied down and right will do:
Excel Formula:
=IF(C2="","",XLOOKUP(C2,$B$2:$B$120,C$2:C$120,"",0))

Of course adjust 120 to your last row in a list.


PS in sample data there are only few employees with Level 2 filled and only one with Level 3:
row 9111540263115406061154061820016291
 
Upvote 0
If I understood well, such a formula copied down and right will do:
Excel Formula:
=IF(C2="","",XLOOKUP(C2,$B$2:$B$120,C$2:C$120,"",0))

Of course adjust 120 to your last row in a list.


PS in sample data there are only few employees with Level 2 filled and only one with Level 3:
row 9111540263115406061154061820016291
Hi, thank you for your recommendation, I tried your formula but this is what I got, can you pls. check and see if I can fix anything?

1710522786438.png
 
Upvote 0
Whoops, I copied data with row numbers in first column. So adjust column letters to read:
Excel Formula:
=IF(B2="","",XLOOKUP(B2,$A$2:$A$120,B$2:B$120,"",0))
 
Upvote 0
Whoops, I copied data with row numbers in first column. So adjust column letters to read:
Excel Formula:
=IF(B2="","",XLOOKUP(B2,$A$2:$A$120,B$2:B$120,"",0))
I believe the formula you're suggesting is not what I actually needed, if you can check the green rows of the correct hierarchy vs. what your formula is suggesting, you'll get what I actually need:

create a hierarchy.xlsx
ABCDEFGH
1EE IDManager IDManagement Level 1Management Level 2Management Level 3Management Level 4Management Level 5Management Level 6
2100601692002070450001602     
310178832115355411154046820020704    
41063840250000503      
51065248511595721      
61065348520017465      
71067323150000155      
81086211150000153      
91109067850000254      
101111590511589682      
111114904611588799      
121122457250001103      
1311262318115355411154046820020704    
141142815720011901      
151148347620017024      
16114971871006016920020704     
171150685120020242      
181150847011545638      
1911512684114971871006016950001602    
2011512901114971871006016950001602    
2111513330114971871006016950001602    
221151344611741241      
231151498611611806      
241152020320016654      
2511535541115404685000025250001602    
261153555311543214      
271153556520016640      
281153581211545563      
291153581411543214      
301153714611739111      
31115373991006016920020704     
321153845020019675      
331153852711595031      
341153856611595213      
351153859020009235      
361153859211542391      
37115386011065348520017465     
381153860420020218      
391153861111548384      
401153862820019410      
411153886811595307      
421153887211543214      
431153889211540810      
441153892611594879      
451153894311543855      
461153896320013089      
471153896750000935      
481153897011595008      
491153897911688035      
501153898411581442      
511153898950002237      
521153900111540702      
531153901450001584      
541153906111540665      
551153909611557496      
561153909811595213      
571153916811595209      
581153918511544247      
591153919211541947      
601153920011542524      
611153920320017465      
621153978320020450      
631153978411602773      
641153979050000152      
651153979311628642      
661153979811595307      
67115402581153900111540702     
681154026220007077      
69115402631154060611540618     
701154028920013248      
711154029211542397      
721154032711544140      
731154034111545360      
741154034920006166      
751154039411595057      
761154040820011856      
771154041820006793      
78115404281154058420000086     
791154044111542352      
8011540442115404685000025250001602    
811154045020016605      
82115404685000025220020704     
831154047020005830      
841154050120013248      
851154054111544247      
86115405631154034111545360     
871154058320017691      
881154058420000086      
89115406061154061811538813     
901154061520016803      
911154061811538813      
921154063250001656      
931154064211594944      
941154064611542504      
951154065111595213      
961154065520000086      
972001996520016291      
98500002522002070450001602     
992002070450001602      
100Sample of correct hierarchy
101EE IDManager IDManagement Level 1Management Level 2Management Level 3Management Level 4Management Level 5Management Level 6
10210178832115355415000160220020704500002521154046811535541
Sheet4
Cell Formulas
RangeFormula
C2:H99C2=IF(B2="","",XLOOKUP(B2,$A$2:$A$99,B$2:B$99,"",0))


Here's what your formula is showing vs. what the correct heirarchy is showing:

EE IDManager IDManagement Level 1Management Level 2Management Level 3Management Level 4Management Level 5Management Level 6
10178832115355411154046820020704
10178832115355415000160220020704500002521154046811535541
 
Upvote 0
Can you explain the steps in words of how you got each of those particular values in the row 103 green cells for columns B,C,D,E,F,G,H?
 
Upvote 0
Please prepare sample file with just few, may be 20 lines and "easy to track numbers" like just 10000001 to 10000020. Or describe in words how hierarchy is to be written.

I used such scheme:
main ID is in column A row x. column B is direct manager for Ax. so I look for column Bx value in column A, and if it is found in row y, I write in column Cx (higher level manager) what is in found By Then I look for Cx in column A and if it is found in row z then I write Bz in Dx (even higher level manager), then look for Dx in column A ...
 
Upvote 0
Can you explain the steps in words of how you got each of those particular values in the row 103 green cells for columns B,C,D,E,F,G,H?
Hi, this is a hierarchy management, what the formula should do is taking column B (employee’s manager) and looping into the whole column to see the highest manager then update column C, then formula in column D, consider the column C and takes the below level manager under C and update, then we continue the same process in other columns till we get blank/0
Hope I could clarify and explain what I need.
 
Upvote 0
This explanation sounds as my approach. Have you changed 120 into your final row.
And let me say again that in my opinion testing will be easier with sample data - some 20, may be 30 rows as described in post #8
 
Upvote 0

Forum statistics

Threads
1,223,888
Messages
6,175,205
Members
452,618
Latest member
Tam84

We've detected that you are using an adblocker.

We have a great community of people providing Excel help here, but the hosting costs are enormous. You can help keep this site running by allowing ads on MrExcel.com.
Allow Ads at MrExcel

Which adblocker are you using?

Disable AdBlock

Follow these easy steps to disable AdBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the icon in the browser’s toolbar.
2)Click on the "Pause on this site" option.
Go back

Disable AdBlock Plus

Follow these easy steps to disable AdBlock Plus

1)Click on the icon in the browser’s toolbar.
2)Click on the toggle to disable it for "mrexcel.com".
Go back

Disable uBlock Origin

Follow these easy steps to disable uBlock Origin

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back

Disable uBlock

Follow these easy steps to disable uBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back
Back
Top