Forum Discussion
Add column with the path&filename
If my understanding is correct, I would use a parameter for the full file/path-spec.
Let's name it "FullPathSpec" and set it to: "C:\Users\DM2088\Downloads\Megalist (20220107).csv".
Then you reference this parameter twice:
First to import the data:
Csv.Document(File.Contents( FullPathSpec ),[Delimiter=" ", Encoding=1200, QuoteStyle=QuoteStyle.None])
(Note that I've removed the Columns parameter here, as this will often cause trouble)
Second to add itself in a column:
Table.AddColumn(#"Sales", "PathAndFilename", each FullPathSpec )
The path and filename were given as an example.
I do NOT know it.
From start....
I'm in Excel and want to import a File.
I go: Data>Obtain Data>From text/CSV and I select the file I want from any folder I want.
Once selected, I click "Transform Data" which opens up the Power Query Editor.
I do my transformation (remove column, move them around, change formatting...) and then, I would like to ADD a column that specify the Filename and Path of the file I'm working on.
Once I close and load the data, it returns to Excel with my transformation and the newly added column that specifies the file and path of that dataset.
Could be ANY file or ANY folder. It is dynamic.
Again, the information of the selected file and path is in the APPLIED STEP > SOURCE but I do not know how to extract it.
Thank you for your support
- lbendlin4 years agoSuper User
ImkeF I had experimented with Value.Metadata(Source) but the Path attribute comes back empty, and I don't know if that is even supported in Excel.
DanFromMontreal Does Power Query for Excel give you the option to connect to a folder rather than a file?