Forum Discussion
comish4lif2
Advocate II
3 years agoExtract 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 ...
- 3 years ago
Hi,
I understand your Source step equals to "Csv.Document(File.Contents(..."
Copy paste the function below and invoke it in your Source instead.(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 FileNameColumnHope it helps.
Payeras_BI
Solution Sage
3 years agoHi,
I understand your Source step equals to "Csv.Document(File.Contents(..."
Copy paste the function below and invoke it in your Source instead.
(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.