Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to use SQL Server stored procedures in Microsoft PowerBI?

I want to generate reports from my SQL Server tables.

I have some already made stored procedures that I would like to use to generate reports from.

I haven't found a way to do so.

Only by rewriting the queries.

Thanks :)

like image 443
AsafSavich Avatar asked Jun 02 '16 10:06

AsafSavich


5 Answers

To execute your SP in Power BI-->

1.In SQL Server right click on your SP and select Execute. Your code is executed and a new query window opens up which was responsible for execution. Copy that Query.

2.In Power BI Query Editor, select New Source-->SQL Server. After giving the server and database, in the same window click on "Advanced Options", paste the query in the "SQL Statement" that opened up. Check "Navigate using full hierarchy" and click OK.

3.You will see data for the parameters you passed in SP only.

  1. On Applying these changes, you will see the dataset for this in Power BI Desktop from where you can create reports.

NOTE: This works in"Import Query" option.

Hope this works for you as it did for me, Cheers!

like image 123
Radhieka Avatar answered Sep 30 '22 19:09

Radhieka


You can use openquery. The following syntax will work with both import data and direct query methods in Power BI Desktop.

SELECT *
FROM OPENQUERY ([server name],
'EXEC dbname.dbo.spname @parametername = ''R1''');

enter image description here

like image 34
Niraj Avatar answered Sep 30 '22 19:09

Niraj


Expand the Advanced options in the Get Data -> SQL Server dialog, and write a SQL Statement to execute your stored procedure such as:

EXEC [dbo].[usp_NameOfYourStoredProcedure]

execute stored procedure in Power BI

like image 39
C. Augusto Proiete Avatar answered Sep 30 '22 20:09

C. Augusto Proiete


Firstly I think its best to make the point out that Power BI isn't Reporting Services, it expects to be given existing table data or views that you then model within it's own environment before creating your dashboards.

If you can get Power BI to do the work of your stored procedures. Once you have your data model defined within Power BI it can be reused.

There is a great introduction course for this on the Power BI website:

https://powerbi.microsoft.com/en-us/guided-learning/powerbi-learning-2-1-intro-modeling-data/

like image 28
Paul Andrew Avatar answered Sep 30 '22 21:09

Paul Andrew


"Hi,

  1. In an Excel workbook, open the ""Power Query"" tab.
  2. Then choose the “From Database” drop down button and select “From SQL Server Database”
  3. Fill in the Server and Database textboxes and click OK
  4. In the Navigator window, double-click the desired table
  5. In the Query Editor window, click on to the column to be displayed.
  6. Click close and select the ""Load"" button
  7. Connect to stored procedures.
  8. Create another power window and fill in the server and database textboxes.
  9. In the SQL statement textbox, type “EXECUTE  Procedure_Name”
  10. Click Close and Load button "
like image 26
sqlprogrammers Avatar answered Sep 30 '22 21:09

sqlprogrammers