+ Reply to Thread
Results 1 to 13 of 13

Finding parent in a hierarchy

  1. #1
    Registered User
    Join Date
    08-16-2013
    Location
    Canada
    MS-Off Ver
    Office 365
    Posts
    51

    Finding parent in a hierarchy

    Hello,

    I'm trying to find a simple solution to finding the parent value in a hierarchy type table of data. I've attached a sample of my data. For each cell, I need to know what the parent level is. There can and is a "one to many" relationship of parent to children.

    If anyone has a solution to this, that would be great!

    TIA.
    Attached Files Attached Files

  2. #2
    Forum Contributor
    Join Date
    11-05-2019
    Location
    Tiki Island, TX
    MS-Off Ver
    Office 365
    Posts
    168

    Re: Finding parent in a hierarchy

    I have solved for this before but "simple" was not how it was solved. When you have a tree like this and you are trying to find a parent there are 3 approaches you can take.
    If it is a consistent and standard tree where the parents are always in the correct column just to the left of the column you are testing for - you can try nested offset and match formulas to get to the parent. The challenge is looking up instead of down which is what has to happen in your data.
    If it is more complicated than that you can use VBA to get there by reading each cell and testing for the first data cell above it that works or copying the blank parents down.
    A newer option is to load the table into powerquery using the data tab and use that functionality to get the parent to cascade down the columns.
    The best possible option is really to have the hierarchy tree export in such a way that the parents copy downward and that is one way to approach the macro version of this answer.

  3. #3
    Registered User
    Join Date
    08-16-2013
    Location
    Canada
    MS-Off Ver
    Office 365
    Posts
    51

    Re: Finding parent in a hierarchy

    Thanks David, any chance you can give an example of the offset/match formula?

    If not, I'll have to try powerquery. Unfortunately, this data is a dump out of SAP into a tab doc.

  4. #4
    Forum Contributor
    Join Date
    11-05-2019
    Location
    Tiki Island, TX
    MS-Off Ver
    Office 365
    Posts
    168

    Re: Finding parent in a hierarchy

    Attached is a file that demonstrates it in PowerQuery. Just make a PowerQuery table from the source data called source. Then make another table with the code below in the advanced editor to create the table with a parent.
    Please Login or Register  to view this content.
    Attached Files Attached Files

  5. #5
    Forum Moderator
    Join Date
    01-21-2014
    Location
    St. Joseph, Illinois U.S.A.
    MS-Off Ver
    Office 365 v 2403
    Posts
    13,406

    Re: Finding parent in a hierarchy

    Formula solution try
    Formula: copy to clipboard
    Please Login or Register  to view this content.
    Dave

  6. #6
    Registered User
    Join Date
    08-16-2013
    Location
    Canada
    MS-Off Ver
    Office 365
    Posts
    51

    Re: Finding parent in a hierarchy

    Thanks for the help

  7. #7
    Registered User
    Join Date
    08-16-2013
    Location
    Canada
    MS-Off Ver
    Office 365
    Posts
    51

    Re: Finding parent in a hierarchy

    What is the ("zzzz") representing?

  8. #8
    Forum Contributor
    Join Date
    10-30-2019
    Location
    Bistrita, Romania
    MS-Off Ver
    2019; 365
    Posts
    231

    Re: Finding parent in a hierarchy

    Quote Originally Posted by FlameRetired View Post
    Formula solution try
    Formula: copy to clipboard
    Please Login or Register  to view this content.
    Fyi this is array formula (use CTRL+SHIFT+ENTER to activate).
    To show your appreciation
    Click ★ Add reputation!

  9. #9
    Forum Moderator
    Join Date
    01-21-2014
    Location
    St. Joseph, Illinois U.S.A.
    MS-Off Ver
    Office 365 v 2403
    Posts
    13,406

    Re: Finding parent in a hierarchy

    Quote Originally Posted by Mackay2m View Post
    What is the ("zzzz") representing?
    It is a text string very likely to be have a "larger" value than anything in the growing range that follows behind. For example in cell J6 if you highlight just this part in the formula bar INDEX($A$1:$G6,,MATCH(1,--($A6:$G6<>""),0)-1) and hit the F9 function key you will see an array of 0s and a text value

    {0;0;0;0;"NCC_RSCH";0}

    Since LOOKUP attempting to match the text string "zzzz" it ignores the numbers and returns the left-most string in that array that is less than or equal to "zzzz". If it were numbers you were expecting LOOKUP to return you would use an appropriately large number instead of "zzzz".

    Does that help?

    Quote Originally Posted by Mrrrr View Post
    Fyi this is array formula (use CTRL+SHIFT+ENTER to activate).
    Actually it didn't require CSE at my end. Have you tried it? LOOKUP seldom require it.
    Last edited by FlameRetired; 11-19-2019 at 04:56 PM.

  10. #10
    Forum Contributor
    Join Date
    10-30-2019
    Location
    Bistrita, Romania
    MS-Off Ver
    2019; 365
    Posts
    231

    Re: Finding parent in a hierarchy

    Yes, I've tried it and thought of CSE when it returned the #VALUE error.

  11. #11
    Forum Moderator
    Join Date
    01-21-2014
    Location
    St. Joseph, Illinois U.S.A.
    MS-Off Ver
    Office 365 v 2403
    Posts
    13,406

    Re: Finding parent in a hierarchy

    Hmm. It's working in the attached.
    Attached Files Attached Files

  12. #12
    Registered User
    Join Date
    08-16-2013
    Location
    Canada
    MS-Off Ver
    Office 365
    Posts
    51
    Quote Originally Posted by FlameRetired View Post
    Hmm. It's working in the attached.
    Thanks! It works!

  13. #13
    Forum Moderator
    Join Date
    01-21-2014
    Location
    St. Joseph, Illinois U.S.A.
    MS-Off Ver
    Office 365 v 2403
    Posts
    13,406

    Re: Finding parent in a hierarchy

    Good deal. You are welcome. Thank you for the feedback.

    If that takes care of your original question, please select Thread Tools from the menu link above and mark this thread as SOLVED.

+ Reply to Thread

Thread Information

Users Browsing this Thread

There are currently 1 users browsing this thread. (0 members and 1 guests)

Similar Threads

  1. [SOLVED] Organizational hierarchy from parent
    By Imbizile in forum Excel Programming / VBA / Macros
    Replies: 6
    Last Post: 06-30-2018, 02:58 AM
  2. Average value of a parent in an hierarchy
    By nik.rao in forum Excel Formulas & Functions
    Replies: 3
    Last Post: 01-08-2018, 01:01 AM
  3. [SOLVED] Finding how many child records for a given parent record
    By mq1973 in forum Excel Formulas & Functions
    Replies: 7
    Last Post: 10-03-2017, 11:53 AM
  4. How do I convert column hierarchy to flat file hierarchy
    By tbucki1 in forum Excel Formulas & Functions
    Replies: 19
    Last Post: 09-21-2016, 09:33 PM
  5. Formula for finding parent equipment from euipment
    By zkamanhal in forum Hello..Introduce yourself
    Replies: 1
    Last Post: 11-09-2015, 04:47 AM
  6. Finding a cell value in another workbook and copying parent value of it in same sheet
    By Pankaj Sonawane in forum Excel Programming / VBA / Macros
    Replies: 0
    Last Post: 08-15-2010, 12:21 PM
  7. [SOLVED] finding the parent row of a cell in VBA
    By Andrew Marshall in forum Excel Programming / VBA / Macros
    Replies: 3
    Last Post: 01-18-2005, 09:06 AM

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts

Search Engine Friendly URLs by vBSEO 3.6.0 RC 1