Forum Discussion
Zdenek_Moravec
Feb 09, 2021Brass Contributor
Power Query - Split folder path with different structure into same columns
Dear colleagues, I want to create a list of folders and files and split the folder names into columns. Unfortunatelly the structure of all subfolders is not the same. Example: C:\EUROPE\GERMANY\20...
- Feb 09, 2021
Slightly different variant (without transition from letter to number), but with same assumption we have only 4 parts and only second one (country) could be missed.
let Source = Excel.CurrentWorkbook(){[Name="Table1"]}[Content], #"Exclude Drive" = Table.AddColumn( Source, "path", each Text.AfterDelimiter([FileName], ":\"), type text ), #"Get Region" = Table.SplitColumn( #"Exclude Drive", "path", Splitter.SplitTextByEachDelimiter({"\"}, QuoteStyle.Csv, false), {"Region", "Txt"} ), #"Get File" = Table.SplitColumn( #"Get Region", "Txt", Splitter.SplitTextByEachDelimiter({"\"}, QuoteStyle.Csv, true), {"Txt", "File"} ), #"Get Country" = Table.AddColumn( #"Get File", "Country", each Text.BeforeDelimiter([Txt], "\", {0, RelativePosition.FromEnd}), type text ), #"Get Year" = Table.AddColumn( #"Get Country", "Year", each Text.AfterDelimiter([Txt], "\", {0, RelativePosition.FromEnd}), type text ), #"Keep Final" = Table.SelectColumns( #"Get Year", {"Region", "Country", "Year", "File"} ) in #"Keep Final"
Zdenek_Moravec
Feb 09, 2021Brass Contributor
Hello SergeiBaklan
Thank You for the next new functions for me. Text.AfterDelimiter and Text.BeforeDelimiter look flexible for this kind of scenario. I will play with these functions, with regard to the fact above, that the countries are after the years.
SergeiBaklan
Feb 10, 2021Diamond Contributor
That's all in user interface, you may call them both in Transform and Add Column under Extract.
- Zdenek_MoravecFeb 10, 2021Brass Contributor
- SergeiBaklanFeb 11, 2021Diamond Contributor
Zdenek_Moravec , glad to help