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
jaryszek
Post Prodigy
Post Prodigy

How to dynamically create power queries in a loop for each existing table in a folder?

Hello Guys,

I have code which is retriving all tables in a folder:

jaryszek_0-1742554904886.png

Now i can filter first table and have it as sepetarated query. 
But what i want to do is to create all queries automatically for me in a loop.

Something like :
1. Loop through all tables within folder
2. Create seperate query for each table 

How to automate it?

Best,
Jacek

1 ACCEPTED SOLUTION

Hi @jaryszek,
Thanks for reaching out to the Microsoft fabric community forum.

TMDL (Tabular Model Definition Language) is used to define and manage Power BI datasets and models programmatically. They provide a structured way to represent tables, relationships, measures, and other metadata in a model.
So TMDL alone cannot create multiple queries from a single query; it is primarily used for defining and managing dataset structures rather than dynamically generating multiple queries.

If we want to create multiple queries from a single query, we need to integrate Python or PowerShell scripting to automate the generation of .tmdl files, which can then be imported into Power BI, followed by refreshing the dataset to apply the changes.

 

If you find this post helpful, please mark it as an "Accept as Solution" and consider giving a KUDOS. Feel free to reach out if you need further assistance.
Thanks and Regards

View solution in original post

5 REPLIES 5
Chewdata
Super User
Super User

Hey!

I am affraid that it is not possible to create seperate new queries for each file from one central query. 

Thanks! 

what about programatically approach like for example via tmdl files?

Best,
Jacek

Hi @jaryszek,
Thanks for reaching out to the Microsoft fabric community forum.

TMDL (Tabular Model Definition Language) is used to define and manage Power BI datasets and models programmatically. They provide a structured way to represent tables, relationships, measures, and other metadata in a model.
So TMDL alone cannot create multiple queries from a single query; it is primarily used for defining and managing dataset structures rather than dynamically generating multiple queries.

If we want to create multiple queries from a single query, we need to integrate Python or PowerShell scripting to automate the generation of .tmdl files, which can then be imported into Power BI, followed by refreshing the dataset to apply the changes.

 

If you find this post helpful, please mark it as an "Accept as Solution" and consider giving a KUDOS. Feel free to reach out if you need further assistance.
Thanks and Regards

bhanu_gautam
Super User
Super User

@jaryszek , Try using

m
let
// Step 1: Retrieve all files in the folder
Source = Folder.Files("C:\YourFolderPath"),

// Step 2: Filter only the files you need (e.g., CSV files)
FilteredFiles = Table.SelectRows(Source, each Text.EndsWith([Extension], ".csv")),

// Step 3: Loop through each file and create a query
CreateQueries = List.Transform(FilteredFiles[Content], each
let
// Get the file name without extension
FileName = Text.BeforeDelimiter(Text.AfterDelimiter([Name], "\"), ".csv"),

// Load the content of the file
FileContent = Csv.Document(_, [Delimiter=",", Columns=10, Encoding=1252, QuoteStyle=QuoteStyle.None]),

// Create a named query
NamedQuery = Table.RenameColumns(FileContent, {{"Column1", FileName}})
in
NamedQuery
)
in
CreateQueries




Did I answer your question? Mark my post as a solution! And Kudos are appreciated

Proud to be a Super User!




LinkedIn






Thanks, but this will create list of queries within one query.

What i want to do is to automate process and create new queries each for file. 
Not creating one query but multiple automatically.


Best,
Jacek

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.