Skip to main content
cancel
Showing results for 
Search instead for 
Did you mean: 

Get certified in Microsoft Fabric—for free! For a limited time, get a free DP-600 exam voucher to use by the end of 2024. Register now

Reply
comish4lif2
Advocate II
Advocate II

Extract Text from Name of File being Imported

Is there an straightforward way in PQ or via a formula, new column, or measure to get the text from the name of the file being imported?

Or do I have to redo a few things and reimport this as a folder import??

1 ACCEPTED SOLUTION
Payeras_BI
Super User
Super User

Hi,

I understand your Source step equals to "Csv.Document(File.Contents(..."
Copy paste the function below and invoke it in your Source instead.

Payeras_BI_0-1686926713274.png

 

(Path as text) => 
let
FileName =  Text.BetweenDelimiters(Path, "_", ".txt", {0, RelativePosition.FromEnd}, 0),
Txt = Csv.Document(File.Contents(Path),[Delimiter=";", Encoding=1252, QuoteStyle=QuoteStyle.None]),
PromoteHeaders = Table.PromoteHeaders(Txt, [PromoteAllScalars=true]),
FileNameColumn = Table.AddColumn(PromoteHeaders, "FileName", each FileName)
in
FileNameColumn

 

Hope it helps.

 

If this post answered your question, please mark it as a solution to help other users find useful content.
Kudos are another nice way to acknowledge those who tried to help you.

J. Payeras
Mallorca, Spain

View solution in original post

3 REPLIES 3
Payeras_BI
Super User
Super User

Hi,

I understand your Source step equals to "Csv.Document(File.Contents(..."
Copy paste the function below and invoke it in your Source instead.

Payeras_BI_0-1686926713274.png

 

(Path as text) => 
let
FileName =  Text.BetweenDelimiters(Path, "_", ".txt", {0, RelativePosition.FromEnd}, 0),
Txt = Csv.Document(File.Contents(Path),[Delimiter=";", Encoding=1252, QuoteStyle=QuoteStyle.None]),
PromoteHeaders = Table.PromoteHeaders(Txt, [PromoteAllScalars=true]),
FileNameColumn = Table.AddColumn(PromoteHeaders, "FileName", each FileName)
in
FileNameColumn

 

Hope it helps.

 

If this post answered your question, please mark it as a solution to help other users find useful content.
Kudos are another nice way to acknowledge those who tried to help you.

J. Payeras
Mallorca, Spain
Payeras_BI
Super User
Super User

Hi @comish4lif2 ,

Assuming the file name is part of your Source step you could add a column extracting it using any of the functions you have available.

For instance: 

Text.BetweenDelimiters(Source,"\",".")

 

If this post answered your question, please mark it as a solution to help other users find useful content.
Kudos are another nice way to acknowledge those who tried to help you.

J. Payeras
Mallorca, Spain

Is the file name part of my source step? 

If I import a txt file, how do I get from "FIlename_06162023.txt" - to "06162023" in its own column.

Helpful resources

Announcements
November Carousel

Fabric Community Update - November 2024

Find out what's new and trending in the Fabric Community.

Live Sessions with Fabric DB

Be one of the first to start using Fabric Databases

Starting December 3, join live sessions with database experts and the Fabric product team to learn just how easy it is to get started.

Las Vegas 2025

Join us at the Microsoft Fabric Community Conference

March 31 - April 2, 2025, in Las Vegas, Nevada. Use code MSCUST for a $150 discount! Early Bird pricing ends December 9th.

Nov PBI Update Carousel

Power BI Monthly Update - November 2024

Check out the November 2024 Power BI update to learn about new features.