Power BI is turning 10, and we’re marking the occasion with a special community challenge. Use your creativity to tell a story, uncover trends, or highlight something unexpected.
Get startedJoin 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.
Hello Guys,
I have code which is retriving all tables in a folder:
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
Solved! Go to 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
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
@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
Proud to be a Super User! |
|
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
This is your chance to engage directly with the engineering team behind Fabric and Power BI. Share your experiences and shape the future.
Check out the June 2025 Power BI update to learn about new features.
User | Count |
---|---|
14 | |
13 | |
8 | |
8 | |
7 |
User | Count |
---|---|
17 | |
13 | |
7 | |
6 | |
6 |