Creating a hierarchy in excel

safniki

New Member
Joined
Sep 11, 2023
Messages
3
Office Version
  1. 2019
Platform
  1. Windows
In an excel sheet I have hierarchy data of units from columns 1-8 (or A-H). The first row is a header. In each row there is only 1 cell that is not empty and that one cell includes the name of a unit. The following example describes the under-over-order relationship of units: Unit A's name is located in e.g. E10 and its superior unit's name is located upwards in the first row from Unit A's row but exactly 1 column left from Unit A's column so in this example the superior unit name will be in column D and somewhere between row 2-9. In column I there is a selfID which is uniqie to each unit. I would like to have an excel formula that provides in column J (parentID) the selfID of the unit's superior unit. If a unit doesn't have a superior unit (because the given unit is in column A and there is no other columns to the left of A) leave the superior unit's cell empty. In the attached photo I already manually filled column J with data that I would expect to get as a result of some excel magic.
excel example.png
 

Excel Facts

Ambidextrous Undo
Undo last command with Ctrl+Z or Alt+Backspace. If you use the Undo icon in the QAT, open the drop-down arrow to undo up to 100 steps.
Hi safniki,

I am not a data formatting expert, but from my limited experience, your data would be easier to use if you had one column for the Level rather than eight columns for the levels. The selfID could be generated somewhat automatically, but it seems like the parentID should be entered by the user for cases where, for example, a department is added at a later date. You want to link it to an earlier parent without have to find the spot and insert a row, etc.
Book1
ABCD
1LevelDescriptionselfIDparentID
21Country11001
32Region110021001
43Department110031002
52Region210141001
63Department210151014
Sheet1

Again, I am not an expert on this topic; there are likely many others in the forum that can offer much better advice.

Hope that helps,

Doug
 
Upvote 0
Hi Doug,

Thanks a lot for your thoughts, however, I wanted to keep the original structure. In another forum I have received a solution that seems to be working. I am sharing it here so it may help others with similar problems:
=LET(_a,INDEX(I$2:I2,XMATCH(TRUE,INDEX($A$2:$H$2,XMATCH(TRUE,A2:H2<>"")-1):INDEX(A2:H2,XMATCH(TRUE,A2:H2<>"")-1)<>"",,-1)),IF(IFERROR(_a=I2,TRUE),"",_a))

Cheers,
Safniki
 
Upvote 0
Solution
Welcome to the MrExcel Message Board!

For future reference
In another forum I have received a solution that seems to be working.

Cross-posting (posting the same question in more than one forum) is not against our rules, but the method of doing so is covered by #13 of the Forum Rules.

Be sure to follow & read the link at the end of the rule too!

Please provide links to any site where you have asked this question.

If you do cross-post in the future and also provide links, then there shouldn’t be a problem.
 
Upvote 0

Forum statistics

Threads
1,215,174
Messages
6,123,451
Members
449,100
Latest member
sktz

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