Power Query - import from folder (csv file) and get file name

aam1932

Board Regular
Joined
Jun 2, 2010
Messages
182
Hai

How to get file name (csv) import from folder before loaded to data table.

Thank in advance
 

Excel Facts

Formula for Yesterday
Name Manager, New Name. Yesterday =TODAY()-1. OK. Then, use =YESTERDAY in any cell. Tomorrow could be =TODAY()+1.
If you set your query to import the csv from a folder (New Query-->From File-->From Folder), the first step in the query will actually list the contents of the folder. In your case, it would be a single csv. Add "[Name]" to the end of the Source step to get a list of file names. Once again, if you have a single file, you will get a single name which is the name of your file.

Below is the code you can put into the Advanced Editor where "C:\Path" is the path to your folder.

Code:
let
    Source = Folder.Files("C:\Path")[Name]
in
    Source

Please note that this is a separate query from your main one. This one is just to get the filename. You can then merge it with your other queries as required.
 
Upvote 0
Sorry,

I know idea how to add the code in my case, probably you can show how to add on to the code below:

let
Source = Folder.Files("D:\GST Recon\Data Extraction from GST by CF MRT - zip file\04 MRT_Period 4\MRT_Period 4\Input"),
#"Removed Other Columns" = Table.SelectColumns(Source,{"Content"}),
#"Combined Binaries" = Binary.Combine(#"Removed Other Columns"[Content]),
#"Imported CSV" = Csv.Document(#"Combined Binaries",[Delimiter="|", Columns=15, Encoding=1252, QuoteStyle=QuoteStyle.None]),
#"Changed Type" = Table.TransformColumnTypes(#"Imported CSV",{{"Column1", type text}, {"Column2", type text}, {"Column3", type text}, {"Column4", type text}, {"Column5", type text}, {"Column6", type text}, {"Column7", type text}, {"Column8", type text}, {"Column9", type text}, {"Column10", type text}, {"Column11", type text}, {"Column12", type text}, {"Column13", type text}, {"Column14", type text}, {"Column15", type text}}),
#"Promoted Headers" = Table.PromoteHeaders(#"Changed Type"),
#"Changed Type1" = Table.TransformColumnTypes(#"Promoted Headers",{{"Principal Fee Amount ", type number}, {"GST Tax Amount ", type number}, {"Gross Amount ", type number}})

in
#"Changed Type1"

Thank you
 
Upvote 0

Forum statistics

Threads
1,215,503
Messages
6,125,175
Members
449,212
Latest member
kenmaldonado

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