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

Join us for an expert-led overview of the tools and concepts you'll need to become a Certified Power BI Data Analyst and pass exam PL-300. Register now.

Reply
Dudu24100
New Member

Import tables with SQL Query

Hi Everyone,

I am attempting to import tables from Snowflake using a SQL statement, specifically targeting tables that contain "PDS" in their names. The objective is to automatically import new tables that include "PDS" in their names and remove those that no longer exist in Snowflake.

Currently, I am using the following query:

SELECT * FROM INFORMATION_SCHEMA.TABLES WHERE TABLE_SCHEMA = 'INFOMART' AND TABLE_NAME LIKE '%EU%'
Dudu24100_1-1750766160488.png

However, this query returns a single table with details of all tables that contain "PDS" in their names.

Any suggestions on how to improve this query to meet my requirements would be greatly appreciated.

Tables in Snowflake :

Dudu24100_0-1750766043369.png

Thank you!

 

4 REPLIES 4
Dudu24100
New Member

Thank you guys for your Input 🙂 

Hi @Dudu24100 ,

Thank you for your response. Please feel free to reach out if you encounter any issues while implementing the provided workarounds. We’re happy to assist you further.

 

Regards,

Dinesh

v-dineshya
Community Support
Community Support

Hi @Dudu24100 ,

Thank you for reaching out to the Microsoft Community Forum.

 

You are using a SQL query to fetch metadata from INFORMATION_SCHEMA.TABLES in Snowflake. However, to dynamically import all tables that contain "PDS" in their name into Power BI, and automatically remove those that no longer exist, you will need to use dynamic import.

To filter for "PDS" tables in the INFOMART schema, please try the below SQL code.

SELECT TABLE_SCHEMA, TABLE_NAME
FROM INFORMATION_SCHEMA.TABLES
WHERE TABLE_SCHEMA = 'INFOMART'
AND TABLE_NAME LIKE '%PDS%'

Note: This will return all table names that contain "PDS".

I am using Power Query to Dynamically Import Tables. I am using the result of the above query as a list of table names, then loop through them dynamically to load data from each table.

Load metadata: Go to Home --> Get Data --> Snowflake. use the above SQL Query

Convert to List of Fully Qualified Table Names. In Power Query, create a new column with below codes.

= [TABLE_SCHEMA] & "." & [TABLE_NAME]

Or you can use below code.

= "EU_DATATEAM_PRO." & [TABLE_SCHEMA] & "." & [TABLE_NAME]

Loop over the tables using Table.Combine

I have created below function for example:

let
LoadPdsTable = (schema as text, name as text) =>
let
Source = Snowflake.Databases("snowflake_account", "warehouse_name"),
db = Source{[Name="EU_DATATEAM_PRO"]}[Data],
schemaObj = db{[Name=schema]}[Data],
table = schemaObj{[Name=name]}[Data]
in
table
in
LoadPdsTable

Apply function across all rows. Add a custom column that uses this function

LoadPdsTable([TABLE_SCHEMA], [TABLE_NAME])

Expand and Combine the Results

Note: Power BI doesn’t support dynamic table loading unless you refresh metadata and re-import via Power Query each time. You can automate refresh via Power BI Service. You cannot do this in DirectQuery mode due to SQL limitations with metadata-based dynamic evaluation.

 

If this information is helpful, please “Accept it as a solution” and give a "kudos" to assist other community members in resolving similar issues more efficiently.
Thank you.

lbendlin
Super User
Super User

Not something you can do in Power Query.  If Snowflake supports the concept of views then you can create a view there that handles the presence/absence of tables,  and then you point Power Query to that view.

Helpful resources

Announcements
Join our Fabric User Panel

Join our Fabric User Panel

This is your chance to engage directly with the engineering team behind Fabric and Power BI. Share your experiences and shape the future.

June 2025 Power BI Update Carousel

Power BI Monthly Update - June 2025

Check out the June 2025 Power BI update to learn about new features.

June 2025 community update carousel

Fabric Community Update - June 2025

Find out what's new and trending in the Fabric community.