Forum Discussion

Anonymous's avatar
Anonymous
Not applicable
4 years ago
Solved

Merge xlsx files and filter empty files.

Hi everyone!

 

I have a query than combine xlsx from a folder of sharepoint online. The files arrives automatically.

 

Files usually have several columns with data. But in some cases arrives files with no info, and the format is just the first row:

"No results returned."

 

How can i filter that files? I guess, when I make Table.SelecRows I should put some kind of filter, but how?

 

Thanks in advance!

 

 

 

let
  Source = SharePoint.Files("https://xxxx.sharepoint.com/teams/xxxx/", [ApiVersion = 15]),
  #"Filtered rows" = Table.SelectRows(Source, each [Folder Path] = "https://xxxx.sharepoint.com/teams/xxxx/folder/folder/"),
  #"Expanded Attributes" = Table.ExpandRecordColumn(#"Filtered rows", "Attributes", {"Size"}, {"Attributes.Size"}),
  #"Filtered hidden files" = Table.SelectRows(#"Expanded Attributes", each [Attributes]?[Hidden]? <> true),
  #"Invoke custom function" = Table.AddColumn(#"Filtered hidden files", "Transform file", each #"Transform file"([Content])),
  #"Renamed columns" = Table.RenameColumns(#"Invoke custom function", {{"Name", "Source.Name"}}),
  #"Removed other columns" = Table.SelectColumns(#"Renamed columns", {"Source.Name", "Transform file"}),
  #"Expanded table column" = Table.ExpandTableColumn(#"Removed other columns", "Transform file", Table.ColumnNames(#"Transform file"(#"Sample file"))),
  #"Transform columns" = Table.TransformColumnTypes(#"Expanded table column", {{XXXX}}),
  #"Replace errors" = Table.ReplaceErrorValues(#"Transform columns", {{XXXXX}})
in
  #"Replace errors"

 

 

 

  • Anonymous's avatar
    Anonymous
    4 years ago

    I find a solution. When I filter the files, I select those that have more than 2 columns.

     

    #"Filtered rows" = Table.SelectRows(Source, each [Folder Path] = "https://xxxx.sharepoint.com/teams/xxxx/xxxx/" and Table.ColumnCount(Excel.Workbook([Content], null, true){[Item = "Sheet_name", Kind = "Sheet"]}[Data])>2)

1 Reply

  • Anonymous's avatar
    Anonymous
    Not applicable

    I find a solution. When I filter the files, I select those that have more than 2 columns.

     

    #"Filtered rows" = Table.SelectRows(Source, each [Folder Path] = "https://xxxx.sharepoint.com/teams/xxxx/xxxx/" and Table.ColumnCount(Excel.Workbook([Content], null, true){[Item = "Sheet_name", Kind = "Sheet"]}[Data])>2)