Extract File Name from a Full Path in a Cell

jgarza0422

New Member
Joined
Apr 8, 2019
Messages
9
I need to see how to extract on the file name from a columns that contains the full path using Power Query.

C:\Users\Desktop\Test\PMOD-0001.doc

Thanks,
 

theBardd

Rules violation
Joined
Jan 21, 2012
Messages
912
It's pretty simple, split the filepath into a list delimited by \, and get the last item in the list

Code:
let
    Source = Excel.CurrentWorkbook(){[Name="Table3"]}[Content],
    #"Added Custom1" = Table.AddColumn(Source, "Custom", each List.Last(Text.Split([Filepath],"\")))
in
    #"Added Custom1"
 

theBardd

Rules violation
Joined
Jan 21, 2012
Messages
912
If you wanted to replace in the original column, you can yse

Code:
let
    Source = Excel.CurrentWorkbook(){[Name="Table3"]}[Content],
    ExtractFilename = Table.TransformColumns(Source, {{"Filepath", each List.Last(Text.Split(_, "\")), type text}})
in
    ExtractFilename
 
Last edited:

Forum statistics

Threads
1,077,614
Messages
5,335,253
Members
399,009
Latest member
twcaddell

Some videos you may like

This Week's Hot Topics

Top