Forum Discussion
Tab name change dynamically updated
- 9 months ago
Hi fbittencourt.
Yes, Power Query allows you to automatically load all sheets from an Excel file, even if you donโt know their names in advance.๐ ๏ธ Power Query code to load all sheets
let
Source = Excel.Workbook(File.Contents("C:\Users\h22012\OneDrive - BNP Paribas\Customers.xlsx"), null, true),// Keep only sheets (ignore named ranges and tables)
OnlySheets = Table.SelectRows(Source, each [Kind] = "Sheet"),// Select relevant columns
SelectedSheets = Table.SelectColumns(OnlySheets, {"Name", "Data"}),// Promote headers and combine all sheets
CombinedData = Table.Combine(
List.Transform(SelectedSheets[Data], each Table.PromoteHeaders(_))
)
in
CombinedData
๐ Explanation
Excel.Workbook(...): loads all elements from the Excel file (sheets, tables, named ranges).
Table.SelectRows(..., each [Kind] = "Sheet"): filters only the sheets.
List.Transform(..., each Table.PromoteHeaders(_)): promotes headers for each sheet.
Table.Combine(...): merges all sheets into a single table.
๐ Optional: Keep sheet name as a column
If you want to track which sheet each row came from, you can add the sheet name before combining:
SheetsWithName = List.Transform(OnlySheets, each Table.AddColumn(Table.PromoteHeaders([Data]), "SheetName", each [Name]))
CombinedData = Table.Combine(SheetsWithName)
โ ๏ธ Important Notes
All sheets should have the same structure (same columns), otherwise Table.Combine may produce errors or nulls.
If structures vary, you may need to standardize them before combining.
โ If this solved your issue, please mark it as the accepted answer to help others in the community.
I agree with you, but the tabs are related to periods ( last 6 months) , after the update it changes the name like ( last 9 months) , so pbi do not recognise automatically...
Define a way to sort the tab names descending and then grab the first item {0}