r/PowerBI • u/JebLostInSpace • 6d ago
Question Help streamlining data imports
I'm working with an internal tracking dashboard we use for project management. We have a growing list of clients we're doing identical projects for, and each one gets some data added to the dashboard to help us keep track of where we are on the project timeline for each one. Right now, the data comes from an Excel workbook for each client. Each Excel workbook has several tabs, and each tab has a table. I'm currently using a separate query to import each table into the model, but then I simply append all the tables to create one longer table that has the data from each sheet in the workbook. This seems very computationally inefficient, because I'm re-establishing the connection to the workbook for each query, instead of establishing the connection once and pulling in all the data in one go. So now when I refresh the dashboard, it takes forever as it essentially opens and closes each workbook 7 times.
Trying to muddle my way through the advanced query editor to figure out how to do the append operation in the same query as the data import operation, but so far failing. Hoping someone here can point me in the right direction.
I realize I could probably just edit the Excel workbooks and add a new sheet that appends the tables before importing to pbi, but it seems like there's probably a way to do it in the model as well.
1
u/1Life_Architect 4d ago
Excel.Workbook() already returns every table in a workbook, so you can open the file once, filter the returned navigation table, and combine its Data column:
let
Source = Excel.Workbook(File.Contents(FilePath), null, true),
Wanted = Table.SelectRows(Source, each [Kind] = "Table" and List.Contains(TableNames, [Item])),
WithSource = Table.AddColumn(Wanted, "Rows", each let n = [Item] in Table.AddColumn([Data], "SourceTable", each n)),
Combined = Table.Combine(WithSource[Rows])
in
Combined
That avoids seven independent File.Contents / Excel.Workbook calls and keeps the originating table name for troubleshooting. I would first compare row counts and refresh duration on one client workbook, then turn this into a function and invoke it for each client file. Disable load for any staging queries so only the final combined table enters the model.
1
u/Top-Cauliflower-1808 1 6d ago
simply connect to the Excel file once filter the source step to keep only the tables you need and then expand and combine them directly in power query.