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

Earn a 50% discount on the DP-600 certification exam by completing the Fabric 30 Days to Learn It challenge.

Reply
Bertrand_fr
Regular Visitor

How to read SQL requests in an Excel file?

Hi everybody,

 

Is there a way in Power BI to read SQL requests in an Excel file and then to dynamically execute them and get the results ?

6 REPLIES 6
Anonymous
Not applicable

Yes, with M, you can iterate over a series of queries and pass those into the Sql.Database() function in the query parameter. Although, if you do this, they'll all be in one "set", so you'll have to decide if you're going to append them or split them out into separate queries.

 

image.pngimage.pngimage.png

 

 

Hi SonnChilds,

 

Thanks a lot for this detailed explanation, works great!

Now I'm trying to find where is the result set?

How can I use it?

Anonymous
Not applicable

Each result set resides in that "Table" value with the yellow text. Try clicking on the word "Table", and you'll add a step navigating to that result set. Alternatively, you can use the split arrows at the top of that column to expand out the tables, but only do this if all of your result sets are of the same structure (i.e. a union).

Ok, I think I understand. But then, it is no possible to have different SQL in my xls source file and then to execute all these sql and get the result automatically by refreshing the report, right?

Anonymous
Not applicable

Well, technically that is possible, but keep in mind that if your SQL changes in any way, and you've used a transformation that references the structure of that query (e.g. a column name), then it'll break.

 

I guess I'm curious as to what you're actually trying to do, because allowing arbitrary SQL from an Excel file to form your data seems kinda brittle. I'd recommend having that SQL logic actually in Power BI itself. I'd have to know more details as to the nature of your queries and how they might change in that Excel file.

I would like to use a list of sql to verify if some problem on the database are resolved, if there's no regression, some basic control of tables, etc. My list of SQL will change of course, and I would like to refresh a report and see if everything's ok.

Helpful resources

Announcements
PBI_APRIL_CAROUSEL1

Power BI Monthly Update - April 2024

Check out the April 2024 Power BI update to learn about new features.