Forum

Combine all tables ...
 
Notifications
Clear all

Combine all tables in workbook and pick up any new ones added

6 Posts
3 Users
0 Reactions
1,245 Views
(@baxbax)
Posts: 125
Estimable Member
Topic starter
 

Hi,

I have a workbook that contains multiple sheets. All of the sheets have identical formats. Each sheet has a table that contains summary data. I want to combine these in to one table for all sheets. Currently I have done this by creating a connection only query for each table and then appending them to get my combined table.

From time to time new sheets will be added to the workbook and I will want to include these in to the combined sheet. 

I know that if you create a query from a folder you can get it to automatically include any new files added to the folder in your query. Is there any similar functionality whereby I can automatically include any new worksheets and tables in to my combined query in the scenario above?

Thanks

 

Mark

 
Posted : 28/09/2017 8:26 am
(@mynda)
Posts: 4761
Member Admin
 

Hi Mark,

You can use the Excel.CurrentWorkbook function to do this.

Create a blank query in your Excel file that contains the tables you want to combine. In the Query Editor formula bar type:

=Excel.CurrentWorkbook()

Press ENTER

This will bring up a list of all the tables, sheets and named ranges in your file. Filter the Name column to select the items you want.

Tip: name all of your tables with a common beginning or ending. e.g. I start the name of all my tables with 'tbl_...' so when I filter the list I can simply specify Text that Begins With; tbl_ and then when I add any new tables they will be included in the query.

Mynda

 
Posted : 28/09/2017 9:06 pm
(@baxbax)
Posts: 125
Estimable Member
Topic starter
 

Thanks Mynda that solution works fine. 

 
Posted : 03/10/2017 1:25 pm
(@jonpeltier)
Posts: 9
Active Member
 

Hi Mynda!

So what if I add a worksheet, and its table has a column that didn't appear in any of the original tables. How do I get the query to recognize new column names? The Expanded Content step only includes the columns in pre-existing tables, even though I included all tables.

 
Posted : 18/07/2020 5:20 pm
(@mynda)
Posts: 4761
Member Admin
 

Hi Jon,

Refresh the query, then click on the cog icon beside the Expanded Content step > click 'load more' > check the box for the new column.

Chris Webb has a post here on how to use a custom function to extract a list of all column names if you want a solution that doesn't require editing the query.

Mynda

 
Posted : 19/07/2020 1:53 am
(@jonpeltier)
Posts: 9
Active Member
 

Thanks, I'll check it out.

 
Posted : 19/07/2020 8:59 am
Share: