简体   繁体   中英

Call a stored procedure from Power BI with a DAX parameter

I'm currently working with Power BI Desktop and SQL Server 2014 on a POC (proof of concept) asked by my superior ( long story short, he said that we were able to do what i'm asking without knowing if it was possible or not... ).

I'm able to see the result of a stored procedure into Power BI when I create a new data source from SQL Server with an SQL instruction (typed in the advanced options)

Query : Sql.Database("SERVER\\INSTANCE", "DatabaseName", [Query="EXECUTE [dbo].[StoredProcedureName]"])
Source : How to use SQL Server stored procedures in Microsoft PowerBI?

I'm also able to display my Windows login using the USERNAME() DAX formula.

We use a lot of stored procedures that take the windows login as a parameter and I know that USERNAME() will not return the same value when the Power BI report will be published online, so I'll need to create a table which will allow me to make the correspondence between the Windows login of the user an his/her Power BI account (an email address).

My question is simple : I want to know if I can call a stored procedure with Power BI, using the result of USERNAME() as a parameter of this stored procedure.

Any help is appreciated, i'm quite stuck at the moment as I didn't use Power BI before...

I don't have a way to do what you're asking to do (grab the result of USERNAME() in DAX, then pass it as a parameter to a stored procedure in the Query Editor).

I also don't know of a way to grab current user information from the Query Editor directly, though this article has some recommendations that may work: https://querypower.com/2017/04/03/4-ways-to-get-username-in-power-query/

What I will say is that Power BI does include Row-Level Security features that I'd strongly recommend considering: https://powerbi.microsoft.com/en-us/documentation/powerbi-admin-rls/

Row-level security can also be implemented in SSAS: https://powerbi.microsoft.com/en-us/documentation/powerbi-desktop-tutorial-row-level-security-onprem-ssas-tabular/

It would require changing your design so that instead of having a stored procedure that accepts a text parameter for the user and then returning data only for that user at the time that the user runs the report, your model would instead pull data for all users, and Power BI would then use RLS to filter the results for the person viewing your report.

An advantage of doing this is that everyone would be accessing a filtered version of the same underlying data model, so the data model itself does not have to fully refresh for each user that comes along (meaning less wait-time for end-users).

Another advantage is that you'd be using the built-in security tools that Power BI offers rather than rolling your own solution with your own mapping tables. (Not that your solution is bad but there's more risk and less support available if you roll your own solution based on your own mapping table.)

Since you're already aware of the USERNAME() parameter in DAX, I imagine you are/were already aware of RLS and had ruled it out (although it was fairly new at the time you asked your question). But since it wasn't mentioned already, I thought I should at least mention it for others who might be trying to do the same thing.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM