Get certified for free when you join Fabric Data Days 2026 and dive into Fabric, Power BI, SQL, AI, and other essential data skills.
Join nowJuly 7 - July 17 | Round 2 of the Power BI Dataviz World Championships. Don't miss your chance! Learn more
Take the following PowerQuery M code:
let
QueryResult = Sql.Database("Server", "database", [Query="select * from MyTable1; select * from MyTable2;"])
in
QueryResult
This will output One table (the result of select * from MyTable1). Is there a way to get the result from both tables, maybe in a list?
Thank you
Solved! Go to Solution.
Then you would have to package them (for example as JSON or XML) and send them over as a string that you would then untangle in Power Query. And this is where the fun stops - Power Query cannot create multiple tables from a single query.
What's your business case?
You input comes from 2 tables. In terms of query cost, the difference between 1 query over 2 tables or 2 queries each over 1 table will be negligible with sufficiently large tables. At the end of the day all data needs to be retrieved.
Why not have 2 sql queries? What are you trying to achieve?
The 2 output tables are based on the same collected data. I want to avoid having to rerun the same expensive query twice.
The SQL Server Query cache should take care of that.
Do these tables have the same structure? In which case you could say
let
QueryResult = Sql.Database("Server", "database", [Query="select * from MyTable1 union all select * from MyTable2;"])
in
QueryResult
The tables do not have the same structure unfortunately.
Then you would have to package them (for example as JSON or XML) and send them over as a string that you would then untangle in Power Query. And this is where the fun stops - Power Query cannot create multiple tables from a single query.
What's your business case?
The query collects data from the database, then based on the data it collected outputs a few tables. This is for temporary reporting purposes. I use power query to read the script, execute it and load it into excel.
My current approach to this is the following:
declare @report int = 0
-- REPLACE THIS IN PowerQuery with set @report = x --
-- CODE --
if @report = 1
select * from Table1
if @report = 2
select * from Table2Then I make a PowerQuery query where @report = 1 and one where @report = 2. This will execute the query twice, which is not ideal.
Converting the output to XML as you suggested might be a better idea
Join us in Barcelona for FabCon and SQLCon, the Fabric, Power BI, SQL, and AI community event. Save €200 with code FABCMTY200.
Join Fabric Data Days 2026: 60 days of free live/on-demand sessions, challenges, study groups, and certification opportunities.