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



## aam1932 (Jun 9, 2016)

Hai

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

Thank in advance


----------



## barjoman (Jun 9, 2016)

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.


```
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.


----------



## aam1932 (Jun 10, 2016)

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


----------



## ImkeF (Jun 10, 2016)

Have a look here & come back if it doesn't work for you: Solved: Retain file name column when using Folder as a dat... - Microsoft Power BI Community


----------

