Skip to main content
cancel
Showing results for 
Search instead for 
Did you mean: 

Data Days is here! Join us now for 60+ days of learning, challenges, and connection. Learn more

Reply
saguado
Frequent Visitor

Connect and append multiple SQL tables programmatically/dinamically

Hi,

 

I have an SQL database where every monthly data is inserted into a table, so all tables in database have the same schema. And I would like to know if its possible to create M query to append all of them dinamically (like CSV folder). Below screenshot shows tables names. I'am able to capture table names with simple SQL SELECT from INFORMATION_SCHEMA.COLUMNS, this is giving me a table with all the table names, but don't know how to iterate, connect and append all of them. Thanks in advance for any help or support.

 

S.

 

saguado_0-1654763935667.png

 

1 ACCEPTED SOLUTION

 

Ok, fair enough, but there must still be someone managing the DB that can create a Stored Procedure or similar to combine all these tables.

 

Anyway, that aside, to do this in PQ you do the following:

 

1) Connect to any one of the tables from PQ to generate your Source and Navigation steps.

 

2) Once imported, delete your Navigation step from the Applied Steps list. This should leave you with a table list, something like this:

BA_Pete_0-1654769945814.png

 

3) Filter this list as you would any other table to end up with a list of all the tables you want to append. For your scenario, you would probably apply a filter to the [Name] column something like this:

Text.StartsWith([Name], "HE_")

Leaving the criteria generic like this ensures that the table selection is dynamic as new tables are added.

 

4) Create a custom step like this:

Table.Combine(previousStepName[Data])

 

This should result in a combined table, including all tables that featured in your filtered list.

 

Pete



Now accepting Kudos! If my post helped you, why not give it a thumbs-up?

Proud to be a Datanaut!




View solution in original post

3 REPLIES 3
BA_Pete
Super User
Super User

Hi @saguado ,

 

I would very strongly suggest that you speak with your DBA and get them to store all of this information in a single table on your DB. It's pretty bad form to have tables containing similar data to be segmented like this on a DB, especially by date parameters.

 

I think trying to manage this situation via Power Query would be a coding and performance nightmare.

 

Pete



Now accepting Kudos! If my post helped you, why not give it a thumbs-up?

Proud to be a Datanaut!




Hi Pete,

 

Thanks for yur prompt answer and I fully agree with your comments, but, the issue is that this database is created by a commercial software, and we cannot change this, so I need to find a way to merge them dinamically.

 

S.

 

Ok, fair enough, but there must still be someone managing the DB that can create a Stored Procedure or similar to combine all these tables.

 

Anyway, that aside, to do this in PQ you do the following:

 

1) Connect to any one of the tables from PQ to generate your Source and Navigation steps.

 

2) Once imported, delete your Navigation step from the Applied Steps list. This should leave you with a table list, something like this:

BA_Pete_0-1654769945814.png

 

3) Filter this list as you would any other table to end up with a list of all the tables you want to append. For your scenario, you would probably apply a filter to the [Name] column something like this:

Text.StartsWith([Name], "HE_")

Leaving the criteria generic like this ensures that the table selection is dynamic as new tables are added.

 

4) Create a custom step like this:

Table.Combine(previousStepName[Data])

 

This should result in a combined table, including all tables that featured in your filtered list.

 

Pete



Now accepting Kudos! If my post helped you, why not give it a thumbs-up?

Proud to be a Datanaut!




Helpful resources

Announcements
Fabric Data Days is here Carousel

Fabric Data Days 2026

Don't miss out on Data Days, June 15 through August 7. Learn Fabric, Power BI, SQL, AI and more.

May Power BI Update Carousel

Power BI Monthly Update - May 2026

Check out the May 2026 Power BI update to learn about new features.

Power BI DataViz World Championships carousel

Power BI DataViz World Championships - June 2026

A new Power BI DataViz World Championship is coming this June! Don't miss out on submitting your entry.