Extracting infomation from a string

droot

New Member
Joined
Oct 18, 2018
Messages
36
Office Version
  1. 365
Platform
  1. Windows
Hi,

I have a list of paths that I need to extract infomation from -

u:\Folder1\Folder 2\Folder 3\Info1\Info2\filename_info1_info2.xlsx

<colgroup><col width="625"></colgroup><tbody>
</tbody>

What I need to extract is Info1, Info2 and just the "filename" into individual cells.


I've tried various left right combinations but the Info1,2 and filenames aren't consistent so it might work for 10 pathways but it won't work for the other 30k.

=(RIGHT(C2,LEN(C2)-SEARCH("Info2",C2)-6)) - This is what I tried to extract the filename but having the problem described above. I was planning on using a substitute formula to remove the "info1_info2" from the result to get the part I need. I imagine this isn't the most efficient way to do this.

Hope this made sense and any help will be greatly appreciated.

Thanks!
 
Folder 1 2 and 3 are always the same but Info1 and 2 change and yes the filename is the way I have written it.
 
Upvote 0

Excel Facts

Return population for a City
If you have a list of cities in A2:A100, use Data, Geography. Then =A2.Population and copy down.
I've tried the formulas you have provided and got the following results -

1st forumla - "U:\Folder" (missing the second part of folder 1 name)

2nd Formula - "(part of) Folder 1\Folder 2\Folder 3\Info1\Info2"

3rd Formula - "info2" (from filename_info1_info2)
 
Upvote 0
"-" is used for spacing in the filename.

eg. big-bad-wolf_info1_info2.xlsx
 
Upvote 0
The formula is using the characters _ . \ to parse the string. so if those aren't in the file name, the formula won't work.

I copied the wrong formula for the filename earlier, this should be it.

=TRIM(RIGHT(SUBSTITUTE(TRIM(LEFT(SUBSTITUTE(TRIM(LEFT(SUBSTITUTE(TRIM(RIGHT(SUBSTITUTE(B2,"",REPT(" ",255)),255)),".",REPT(" ",255)),255)),"_",REPT(" ",255)),255)),"",REPT(" ",255)),255))

The - should be included in the output of the filename.
 
Last edited:
Upvote 0
This is the output for that formula -

<colgroup><col width="439"></colgroup><tbody>
</tbody>
"u:\Folder1\Folder 2\Folder3\info1\info2\file-name

The "_info1_info2.xlsx" has been removed.


Maybe this will better explain the path format

u:\public_folder\company name 2019\Folder3\info 1\Info_2\client-name-here_info1_info2.xlsx



<colgroup><col width="625"></colgroup><tbody>
</tbody>
 
Upvote 0
Somehow managed to get permission to install power query sooner than expected.

I've renamed the path column to src but i'm getting the following - Expression.Error: The column 'src' of the table wasn't found. Details: src
 
Upvote 0
replaced "source" with the sheet name and now have the following error - Expression.Error: A cyclic reference was encountered during evaluation.

Sorry, I've never used this before so probably missing something obvious.

let
Source = Excel.Workbook(File.Contents("C:\Users\droot\Desktop\US_clients.xlsx"), null, true),
#"Extracted Text After Delimiter" = Table.TransformColumns(deduped, {{"src", each Text.AfterDelimiter(_, "", 3), type text}}),
#"Split Column by Delimiter" = Table.SplitColumn(#"Extracted Text After Delimiter", "src", Splitter.SplitTextByDelimiter("", QuoteStyle.Csv), {"src.1", "src.2", "src.3"}),
#"Inserted Text Before Delimiter" = Table.AddColumn(#"Split Column by Delimiter", "Text Before Delimiter", each Text.BeforeDelimiter([src.3], "_"), type text),
#"Inserted Text After Delimiter" = Table.AddColumn(#"Inserted Text Before Delimiter", "Text After Delimiter", each Text.AfterDelimiter([src.3], "."), type text),
#"Merged Columns" = Table.CombineColumns(#"Inserted Text After Delimiter",{"Text Before Delimiter", "Text After Delimiter"},Combiner.CombineTextByDelimiter(".", QuoteStyle.None),"filename"),
#"Removed Columns" = Table.RemoveColumns(#"Merged Columns",{"src.3"})
in
#"Removed Columns"
 
Upvote 0
OMG managed to make this work somehow. Power query is amazing!
 
Upvote 0
LOL :) IT agreed with PowerQuery? Impossible! :)
Great you find it useful...

maybe shorter version....

Code:
[SIZE=1]let
    Source = Excel.CurrentWorkbook(){[Name="Table1"]}[Content],
    #"Split Column by Delimiter" = Table.SplitColumn(Source, "src", Splitter.SplitTextByDelimiter("\", QuoteStyle.Csv), {"src.1", "src.2", "src.3", "src.4", "src.5", "src.6", "src.7"}),
    #"Removed Other Columns" = Table.SelectColumns(#"Split Column by Delimiter",{"src.5", "src.6", "src.7"}),
    #"Extracted Text Before Delimiter" = Table.TransformColumns(#"Removed Other Columns", {{"src.7", each Text.BeforeDelimiter(_, "_"), type text}})
in
    #"Extracted Text Before Delimiter"[/SIZE]

srcsrc.5src.6src.7
u:\Folder1\Folder 2\Folder 3\Info1\Info2\filename_info1_info2.xlsxInfo1Info2filename
u:\public_folder\company name 2019\Folder3\info 1\Info_2\client-name-here_info1_info2.xlsxinfo 1Info_2client-name-here
 
Upvote 0

Forum statistics

Threads
1,214,641
Messages
6,120,684
Members
448,977
Latest member
dbonilla0331

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