Forum Discussion

Anonymous's avatar
Anonymous
Not applicable
1 year ago
Solved

Expand data table only for 1st sheet without specifying sheet name

Hi,   I have weekly dataset stored excel files every week and it comes with same format always.  But the thing is it has various sheet names from different uploaders so I cannot filter with specif...
  • v-sdhruv's avatar
    1 year ago

    Hi Anonymous ,
    You can directly start with blank query.
    You can use this query and modify as per your folder name-
    let
    Source = Folder.Files("C:\\Your\\Folder\\Path")                          // Change this to your folder path
    ExcelFiles = Table.SelectRows(Source, each Text.EndsWith([Extension], ".xlsx") or Text.EndsWith([Extension], ".xls")),
    AddFirstSheet = Table.AddColumn(ExcelFiles, "FirstSheet", each try Excel.Workbook([Content], null, true){0}[Data] otherwise null),
    RemoveNulls = Table.SelectRows(AddFirstSheet, each [FirstSheet] <> null),
    ExpandedData = Table.ExpandTableColumn(RemoveNulls, "FirstSheet", Table.ColumnNames(RemoveNulls{0}[FirstSheet])),
    FinalTable = Table.SelectColumns(ExpandedData, {"Name"} & Table.ColumnNames(RemoveNulls{0}[FirstSheet]))
    in
    FinalTable
    This will get you one table with the first sheet from every file
    If column names are inconsistent across sheets, consider normalizing them before combining.
    Hope this helps!