Can I keep the file name column when Combine files in a folder with Power query?

Copper Contributor

clipboard_image_0.png

When I click into the binary content, I will lose the file name column, like the picture below. What can I do to  keep the file name column ? 

 

clipboard_image_1.png

6 Replies

@mengsheng 

If you click on Combine Files on entire table like this

image.png

From Folder connector shall keep file names, like

image.png

If you keep only Content and Name columns result will be without filenames.

@Sergei BaklanThank you for your help. I really can't figure out how to Combine Files on entire table, the file name column will  still be lost if I  didn't delete other columns... I'm using power query built in excel, not Power bi.

@Sergei Baklan unfortunately, that didn't work for me either.  I tried it in Excel as well as PBI Desktop.

@daenos 

Both Power BI Desktop and Excel work exactly the same way, at least latest versions. To be sure

- we use From Folder connection and select folder on local drive

- select table or sheet for the sample file

- query returns 8 columns, from Content to Folder Path

- click on Combine Files icon to the right Content column name

 

If check steps, query generates, among others, these two

    #"Renamed Columns1" = Table.RenameColumns(#"Invoke Custom Function1", {"Name", "Source.Name"}),
    #"Removed Other Columns1" = Table.SelectColumns(#"Renamed Columns1", {"Source.Name", "Transform File"}),

So, it renames Name to Source.Name and returns this column with file names into result.

 

Another scenario if we, for example, select Content and Name and Remove other column. Or whatever else we do. Power Query recognizes that we transform source manually and doesn't insert above two steps automatically. Click on Combine Files and query generates only

    #"Removed Other Columns1" = Table.SelectColumns(#"Invoke Custom Function1", {"Transform File"}),

Transform File column is expanded and we have only transformed range without file names. However, if we would like to keep Name for this scenario as well, on the step

image.png

add Name manually in formula bar

image.png

and file names will be kept.

@@mengshen 

Simple after combining binary in Power Query replace 

achattha_0-1679143559116.png

 

"= Table.SelectColumns(#"Renamed Columns1", {"Source.Name", "Transform File (2)"})"

with 

"= Table.SelectColumns(#"Renamed Columns1", {"Source.Name","Folder Path", "Transform File (2)"})"