Forum Discussion

mengsheng's avatar
mengsheng
Copper Contributor
Aug 26, 2019

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

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 ? 

 

6 Replies

  • achattha's avatar
    achattha
    Copper Contributor

    @@mengshen 

    Simple after combining binary in Power Query replace 

     

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

    with 

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

  • SergeiBaklan's avatar
    SergeiBaklan
    Diamond Contributor

    mengsheng 

    If you click on Combine Files on entire table like this

    From Folder connector shall keep file names, like

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

    • daenos's avatar
      daenos
      Copper Contributor

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

      • SergeiBaklan's avatar
        SergeiBaklan
        Diamond Contributor

        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

        add Name manually in formula bar

        and file names will be kept.

    • mengsheng's avatar
      mengsheng
      Copper Contributor

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

Resources