List with hierarchy-new column with parent

Vilep

New Member
Joined
Jul 14, 2023
Messages
9
Office Version
  1. 365
Platform
  1. Windows
I have a list in a column of Regions. The elements subregions or sub-subregions are identified by "-". There may be one or more levels per region.

I would like to create a column of "Hierarchy of regions", so the "level above being the parent" will show.

The elements are always sorted, so no e.g. row of Europe-England when listing African regions.

Preferably by using "basic formula" in Excel or Power Query.

1689326016589.png
 

Excel Facts

How can you automate Excel?
Press Alt+F11 from Windows Excel to open the Visual Basic for Applications (VBA) editor.
Hi & welcome to MrExcel.
How about
Excel Formula:
=TEXTBEFORE(A2,"-",-1,,,"")
 
Upvote 0
Solution
You can try split:
Excel Formula:
=TEXTSPLIT(A2;"-")
Result looks like this:
split.png
 
Upvote 0
That does not give the expected results that the OP showed.
 
Upvote 0
=TEXTBEFORE(A2,"-",-1,,,"")
Thanks, and thanks a lot. The formula worked very nicely down the rows on my new (one) column in Excel.
Would you possibly know the formula, if new column created during import of data in Power query?

I've now tried creating Custom columns with "Text.BeforeDelimiter", but it looks to me that I need "extra helping columns like "Text.BeforeDelimiter([Regions],"-",1))" for regions before second "-" to retrieve parts of the original column data and then make a new final. This looks not so smart as your one excel formula.
 
Upvote 0
I know very little about PQ & so cannot help with that.
 
Upvote 0
You're welcome & thanks for the feedback.
 
Upvote 0

Forum statistics

Threads
1,215,167
Messages
6,123,401
Members
449,098
Latest member
ArturS75

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