Power BI is turning 10! Tune in for a special live episode on July 24 with behind-the-scenes stories, product evolution highlights, and a sneak peek at what’s in store for the future.
Save the dateEnhance your career with this limited time 50% discount on Fabric and Power BI exams. Ends August 31st. Request your voucher.
Hello Everyone,
I'm looking for an apporach to load data into Power BI from list of SQL queries stored in Postgres database table.
Sr | Query |
1 | Select .... |
2 | Select .... |
3 | Select .... |
4 | Select .... |
Essentially, we need to automate query loading process as list of query will increase/decrease with time & manual addition would not be permanent solution.
Any inputs if this can be achived & appreciate if you can share your experiences in such scenarios.
Hi @Anonymous
You can certainly do this sort of thing by first querying the table containing the queries, then using a function like Value.NativeQuery to execute each query.
I have attached a small PBIX with parameters you could update to test against your database. I have tested this successfully with a PostgreSQL database on my local machine.
I have assumed you want to union the results of the queries. If you want to do something different, you would need to change the final steps of CombinedQueries.
Below is the M code for the queries in the PBIX. The four parameters should be changed as needed for your data source.
// Server
"localhost" meta [IsParameterQuery=true, Type="Text", IsParameterQueryRequired=true]
// Database
"OwenSandbox" meta [IsParameterQuery=true, Type="Text", IsParameterQueryRequired=true]
// Schema
"public" meta [IsParameterQuery=true, Type="Text", IsParameterQueryRequired=true]
// Table
"MyQueries" meta [IsParameterQuery=true, Type="Text", IsParameterQueryRequired=true]
// DatabaseConnection
let
Source = PostgreSQL.Database(Server, Database)
in
Source
// CombinedQueries
let
Source = DatabaseConnection,
QueryTable = Source{[Schema=Schema,Item=Table]}[Data],
#"Add Query Result" = Table.AddColumn(QueryTable, "Query Result", each Value.NativeQuery(DatabaseConnection,[Query],null,[EnableFolding = true])),
#"Select Query Result" = Table.SelectColumns(#"Add Query Result",{"Query Result"}),
// Union the query results. Change as required.
Combine = Table.Combine(#"Select Query Result"[Query Result])
in
Combine
Hopefully that helps a bit! Please post back if needed 🙂
Regards
Check out the July 2025 Power BI update to learn about new features.
This is your chance to engage directly with the engineering team behind Fabric and Power BI. Share your experiences and shape the future.
User | Count |
---|---|
10 | |
7 | |
7 | |
6 | |
6 |