Forum Discussion

CMISAuthority's avatar
CMISAuthority
New Member
4 years ago
Solved

Import a specific range from multiple excel files

I want to import multiple excel files and choose in advance a specific range of columns from the same sheet in all files. range A:Z What is the solution?
  • v-yingjl's avatar
    v-yingjl
    4 years ago

    Hi CMISAuthority ,

    To apply it for all sheets in all files, suggest you to create a folder to store these excel files.

    Create a custom function like this:

    (tab) as table =>
    let
        A = Table.SelectColumns(Table.PromoteHeaders(tab,[PromoteAllScalars = true]),{"cat","val"},MissingField.UseNull)
    in
        A
    
    //You can add you needed column names in {"",""} to select specific columns

    Connect to the folder, get each sheet for each table, invoke the above custom function:

    let
        Source = Folder.Files("C:\Users\Admin\Desktop\xx"),
        #"Added Custom" = Table.AddColumn(Source, "Workbook", each Excel.Workbook([Content])),
        #"Removed Other Columns" = Table.SelectColumns(#"Added Custom",{"Workbook", "Name"}),
        #"Expanded Workbook" = Table.ExpandTableColumn(#"Removed Other Columns", "Workbook", {"Data"}, {"Workbook.Data"}),
        #"Invoked Custom Function" = Table.AddColumn(#"Expanded Workbook", "Custom Function", each #"Custom Function"([Workbook.Data]))
    in
        #"Invoked Custom Function"

    Now you will get the filtered column tables as a new column, you can just keep this table column if you want to expand and combine the values in it as a new table.

     

    Best Regards,
    Community Support Team _ Yingjie Li
    If this post helps, then please consider Accept it as the solution to help the other members find it more quickly.