Formula to create a hierarchy for a list of employees

zinah

Active Member
Joined
Nov 28, 2018
Messages
353
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
 
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.
That is another general description of the overall process (which I am not fully understanding). What I asked for was
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?
That is,
  • explain what you do to get 11535541 in cell B103?
  • explain what you do to get 50001602 in cell C103
  • explain what you do to get 20020704 in cell D103
  • etc
You also used the expression "looping into the whole column to see the highest manager". What is meant by "highest manager"?
 
Upvote 0

Excel Facts

Enter current date or time
Ctrl+: enters current time. Ctrl+; enters current date. Use Ctrl+: Ctrl+; Enter for current date & time.
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
Hi @Kaper thank you so much for your valuable input and great support, I was able to get the exact formula that can serve my purpose, I used LAMBDA formula that did the magic and created the manager hierarchy of each employee. I'm sharing this here so everyone can get the knowledge :)

create a hierarchy.xlsx
ABCDEFGH
2EE IDManager IDManagement Level 1Management Level 2Management Level 3Management Level 4Management Level 5Management Level 6
310060169200207045000160220020704
410178832115355415000160220020704500002521154046811535541
5106384025000050350000503
6106524851159572111595721
7106534852001746520017465
8106732315000015550000155
9108621115000015350000153
10110906785000025450000254
11111159051158968211589682
12111490461158879911588799
13112245725000110350001103
1411262318115355415000160220020704500002521154046811535541
15114281572001190120011901
16114834762001702420017024
171149718710060169500016022002070410060169
18115068512002024220020242
19115084701154563811545638
20115126841149718750001602200207041006016911497187
21115129011149718750001602200207041006016911497187
22115133301149718750001602200207041006016911497187
23115134461174124111741241
24115149861161180611611806
25115202032001665420016654
26115355411154046850001602200207045000025211540468
27115355531154321411543214
28115355652001664020016640
29115358121154556311545563
30115358141154321411543214
31115371461173911111739111
321153739910060169500016022002070410060169
33115384502001967520019675
34115385271159503111595031
35115385661159521311595213
36115385902000923520009235
37115385921154239111542391
3811538601106534852001746510653485
39115386042002021820020218
40115386111154838411548384
41115386282001941020019410
42115386311154068211540682
43115386451154563011545630
44115386505000138350001383
45115386521175123111751231
46115386531154192111541921
47115386672000705920007059
48115386682000821020008210
49115386975000158450001584
50115387171154216811542168
51115387321159521011595210
52115387361159531911595319
53115387411154204411542044
54115387431159521311595213
55115387872001669820016698
56115387971159521311595213
57115388091159521311595213
58115388132001629120016291
59115388582001694720016947
60115388681159530711595307
61115388721154321411543214
62115388921154081011540810
63115389261159487911594879
64115389431154385511543855
65115389632001308920013089
66115389675000093550000935
67115389701159500811595008
68115389791168803511688035
69115389841158144211581442
70115389895000223750002237
71115390011154070211540702
72115390145000158450001584
73115390611154066511540665
74115390812001688220016882
75115390961155749611557496
76115390981159521311595213
77115391681159520911595209
78115391851154424711544247
79115391921154194711541947
80115392001154252411542524
81115392032001746520017465
82115397832002045020020450
83115397841160277311602773
84115397905000015250000152
85115397931162864211628642
86115397945000120050001200
87115397981159530711595307
8811540258115390011154070211539001
89115402622000707720007077
90115402631154060620016291115388131154061811540606
91115402892001324820013248
92115402921154239711542397
93115403271154414011544140
94115403411154536011545360
95115403492000616620006166
96115403941159505711595057
97115404082001185620011856
98115404182000679320006793
9911540428115405842000008611540584
100115404411154235211542352
101115404421154046850001602200207045000025211540468
102115404502001660520016605
1031154046850000252500016022002070450000252
104115404702000583020005830
105115405012001324820013248
106115405411154424711544247
10711540563115403411154536011540341
108115405832001769120017691
109115405842000008620000086
110115405851154197711541977
1111154060611540618200162911153881311540618
112115406152001680320016803
11311540618115388132001629111538813
114115406325000165650001656
115115406421159494411594944
116115406461154250411542504
117115406511159521311595213
118115406552000008620000086
119200199652001629120016291
12050000252200207045000160220020704
121200207045000160250001602
Sheet3 (3)
Cell Formulas
RangeFormula
C3:D3,C120:D120,C113:D113,C111:E111,C107:D107,C103:E103,C101:F101,C99:D99,C90:F90,C88:D88,C38:D38,C32:E32,C26:F26,C20:F22,C17:E17,C14:G14,C5:C13,C15:C16,C18:C19,C23:C25,C27:C31,C33:C37,C39:C87,C89,C91:C98,C100,C102,C104:C106,C108:C110,C112,C114:C119,C121C3=TEXTSPLIT(MID(getBoss(A3,empRange,bossRange),2,999),"|")
Dynamic array formulas.
Named Ranges
NameRefers ToCells
bossRange='Sheet3 (3)'!$B$3:$B$121C3:C121
empRange='Sheet3 (3)'!$A$3:$A$121C3:C121
 
Upvote 0
That is another general description of the overall process (which I am not fully understanding). What I asked for was

That is,
  • explain what you do to get 11535541 in cell B103?
  • explain what you do to get 50001602 in cell C103
  • explain what you do to get 20020704 in cell D103
  • etc
You also used the expression "looping into the whole column to see the highest manager". What is meant by "highest manager"?
Thank you for your feedback and help @Peter_SSs what I'm trying to do is to create manager hierarchy for each employee. The sample result I shared has no formula, it's a manual copy/paste that's why I needed a formula. I was able to find the formula and shared it here so everyone can take advantage and use the same if they have the same issue as I did. Thanks once again!
 
Upvote 0
what I'm trying to do is to create manager hierarchy for each employee.
Yes, you had already said that. What I was asking for was a description in words of how you would manually get the values listed in the green cells. I would still be interested in that.

I was able to find the formula and shared it here so
.. though unfortunately you have not really shared because we don't have the LAMBDA function that you used.

If you update your XL2BB version to the latest version (see my signature block below) then you can include LAMBDA functions in the Mini Sheet data

1711001744229.png
 
Upvote 0
Yes, you had already said that. What I was asking for was a description in words of how you would manually get the values listed in the green cells. I would still be interested in that.


.. though unfortunately you have not really shared because we don't have the LAMBDA function that you used.

If you update your XL2BB version to the latest version (see my signature block below) then you can include LAMBDA functions in the Mini Sheet data

View attachment 108759
I will download the new version later, thanks for highlighting this! As for the LAMBDA, here's the formula:

Excel Formula:
=LAMBDA(employee,empRange,bossRange,LET(boss,XLOOKUP(employee,empRange,bossRange,""),IF(boss="","",getBoss(boss,empRange,bossRange)&"|"&boss)))
 
Upvote 0
Yes, you had already said that. What I was asking for was a description in words of how you would manually get the values listed in the green cells. I would still be interested in that.


.. though unfortunately you have not really shared because we don't have the LAMBDA function that you used.

If you update your XL2BB version to the latest version (see my signature block below) then you can include LAMBDA functions in the Mini Sheet data

View attachment 108759

Here's the full sheet with the LAMBDA formula:

create a hierarchy.xlsx
ABCDEFGH
2EE IDManager IDManagement Level 1Management Level 2Management Level 3Management Level 4Management Level 5Management Level 6
310060169200207045000160220020704
410178832115355415000160220020704500002521154046811535541
5106384025000050350000503
6106524851159572111595721
7106534852001746520017465
8106732315000015550000155
9108621115000015350000153
10110906785000025450000254
11111159051158968211589682
12111490461158879911588799
13112245725000110350001103
1411262318115355415000160220020704500002521154046811535541
15114281572001190120011901
16114834762001702420017024
171149718710060169500016022002070410060169
18115068512002024220020242
19115084701154563811545638
20115126841149718750001602200207041006016911497187
21115129011149718750001602200207041006016911497187
22115133301149718750001602200207041006016911497187
23115134461174124111741241
24115149861161180611611806
25115202032001665420016654
26115355411154046850001602200207045000025211540468
27115355531154321411543214
28115355652001664020016640
29115358121154556311545563
30115358141154321411543214
31115371461173911111739111
321153739910060169500016022002070410060169
33115384502001967520019675
34115385271159503111595031
35115385661159521311595213
36115385902000923520009235
37115385921154239111542391
3811538601106534852001746510653485
39115386042002021820020218
40115386111154838411548384
41115386282001941020019410
42115386311154068211540682
43115386451154563011545630
44115386505000138350001383
45115386521175123111751231
46115386531154192111541921
47115386672000705920007059
48115386682000821020008210
49115386975000158450001584
50115387171154216811542168
51115387321159521011595210
52115387361159531911595319
53115387411154204411542044
54115387431159521311595213
55115387872001669820016698
56115387971159521311595213
57115388091159521311595213
58115388132001629120016291
59115388582001694720016947
60115388681159530711595307
61115388721154321411543214
62115388921154081011540810
63115389261159487911594879
64115389431154385511543855
65115389632001308920013089
66115389675000093550000935
67115389701159500811595008
68115389791168803511688035
69115389841158144211581442
70115389895000223750002237
71115390011154070211540702
72115390145000158450001584
73115390611154066511540665
74115390812001688220016882
75115390961155749611557496
76115390981159521311595213
77115391681159520911595209
78115391851154424711544247
79115391921154194711541947
80115392001154252411542524
81115392032001746520017465
82115397832002045020020450
83115397841160277311602773
84115397905000015250000152
85115397931162864211628642
86115397945000120050001200
87115397981159530711595307
8811540258115390011154070211539001
89115402622000707720007077
90115402631154060620016291115388131154061811540606
91115402892001324820013248
92115402921154239711542397
93115403271154414011544140
94115403411154536011545360
95115403492000616620006166
96115403941159505711595057
97115404082001185620011856
98115404182000679320006793
9911540428115405842000008611540584
100115404411154235211542352
101115404421154046850001602200207045000025211540468
102115404502001660520016605
1031154046850000252500016022002070450000252
104115404702000583020005830
105115405012001324820013248
106115405411154424711544247
10711540563115403411154536011540341
108115405832001769120017691
109115405842000008620000086
110115405851154197711541977
1111154060611540618200162911153881311540618
112115406152001680320016803
11311540618115388132001629111538813
114115406325000165650001656
115115406421159494411594944
116115406461154250411542504
117115406511159521311595213
118115406552000008620000086
119200199652001629120016291
12050000252200207045000160220020704
121200207045000160250001602
solution
Cell Formulas
RangeFormula
C3:D3,C120:D120,C113:D113,C111:E111,C107:D107,C103:E103,C101:F101,C99:D99,C90:F90,C88:D88,C38:D38,C32:E32,C26:F26,C20:F22,C17:E17,C14:G14,C5:C13,C15:C16,C18:C19,C23:C25,C27:C31,C33:C37,C39:C87,C89,C91:C98,C100,C102,C104:C106,C108:C110,C112,C114:C119,C121C3=TEXTSPLIT(MID(getBoss(A3,empRange,bossRange),2,999),"|")
Dynamic array formulas.
Named Ranges
NameRefers ToCells
bossRange=solution!$B$3:$B$121C3:C121
empRange=solution!$A$3:$A$121C3:C121
Lambda Functions
NameFormula
getBoss=LAMBDA(employee,empRange,bossRange,LET(boss,XLOOKUP(employee,empRange,bossRange,""),IF(boss="","",getBoss(boss,empRange,bossRange)&"|"&boss)))
 
Upvote 0
Solution
Here's the full sheet with the LAMBDA formula:
Great, thanks for that. The reason I was asking for description of how you got the values was that the results didn't make sense to me as I was imagining that Management Level 1 was the lowest level but with your function I can now see it means the highest level. So I was looking at the sample results in the wrong order. 😎

As a matter of interest, another way to deal with that leading "|", instead of the MID(...,2,999) structure would be to use this formula in the worksheet

Excel Formula:
=DROP(TEXTSPLIT(getBoss(A3,empRange,bossRange),"|"),,1)
 
Upvote 0
Great, thanks for that. The reason I was asking for description of how you got the values was that the results didn't make sense to me as I was imagining that Management Level 1 was the lowest level but with your function I can now see it means the highest level. So I was looking at the sample results in the wrong order. 😎

As a matter of interest, another way to deal with that leading "|", instead of the MID(...,2,999) structure would be to use this formula in the worksheet

Excel Formula:
=DROP(TEXTSPLIT(getBoss(A3,empRange,bossRange),"|"),,1)
Thank you so much for your great suggestion, I see that your formula is straightforward and easier to digest and remember, I love this platform and the learning experience I get with every question and answers I receive! Thanks for everyone (@Kaper ) who support here and suggested solutions!
 
Upvote 0
You're welcome.

Given the type of data you have, another option would be to use a space as the delimiter in your LAMBDA instead of the "|" character ..
Excel Formula:
=LAMBDA(employee,empRange,bossRange,LET(boss,XLOOKUP(employee,empRange,bossRange,""),IF(boss="","",getBoss(boss,empRange,bossRange)&" "&boss)))

.. then in the worksheet use
Excel Formula:
=TEXTSPLIT(TRIM(getBoss(A3,empRange,bossRange))," ")

BTW, I have changed the 'Mark as solution' to your post since that is the one with the solution to the original question. :)
 
Upvote 0

Forum statistics

Threads
1,215,106
Messages
6,123,122
Members
449,096
Latest member
provoking

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