Can slicers be used a stored procedure parameter in power bi to filter underlying data - powerbi

Can we pass the slicer values as stored procedure paramter when connecting to a sql for developing a PowerBI report so that once its deployed in powerbi service the end user can use slicer to filter the report
I tried to use a stored procedure which uses a date paramter ,but using slicer i am unable pass as a paramter to stored procedure

No. You cannot directly use stored procedures in DirectQuery models. If you use native sql in DirectQuery, it must be "composable", ie Power BI will run
select * from (<your query here>) b
where someslicer=somevalue...
So you can use multi-statement table-valued functions, and you can manipulate the native query using Dynamic M Parameters, and there's a workaround where you use OPENQUERY against a loopback linked server to run a stored procedure. How to use SQL Server stored procedures in Microsoft PowerBI?

Related

How to use parameterized snowflake UDF in Power BI

I have a user defined function in snowflake with arguments and returns a table.
function orders_for_product(varchar,varchar,datetime,datetime)
I want to use this function in Power BI.
What I tried before is:
Creating a view in snowflake. But passing parameters was not possible in view.
As the dataset has many aggregations and date filters on different date columns present in different CTE's, applying filters on PowerBI desktop is giving unexpected output.
The major challenge is that the dataset has to be used in PowerBI Report Builder with parameters values entered by users.

How would I add a WHERE clause to a SQL or Access Data Source in Power BI?

I am evaluating Power BI as a possible tool for publication quality reports that will be distributed to clients. My source databases are in Microsoft SQL and Access.
I am somewhat confused by the Power Query Editor.
As a part of this, we will need to be able to specify the value of a Client Id field and apply a WHERE clause to the SQL and Access data source.
I see that I can filter data on one or more columns. This would be cumbersome if generating reports for a set of individual clients.
I see a Manage Parameters feature on the Home Tab of the Power Query Editor. Can these parameters be compared to values in database tables?
Are there examples of using M or DAX (or anything else) to implement an equivalent WHERE clause?
Do I have to run stored procedures, populate temporary tables and then run Power BI reports?
Here are a few options:
Connect to your database using a Native Database Query. (Related post.)
Connect to a view you create on your database that includes the WHERE clause.
Filter the table in the Query Editor after connecting to it.
Import or DirectQuery the whole table and filter at run time.
In #3, basic filtering usually gets folded into the under-the-hood query that Power BI sends to the database so that this is similar to #1 as far as your database sees.
With #4, it's possible to apply row-level security so that different people have access to different subsets of the data.

PowerBi - Connection Type (DIRECT QUERY or IMPORT DATA) Question

I am working on a PowerBi project and I need some advice/questions on the best way to approach this project. I am tasked to create a dashboard for employee metrics pulled from an onsite SQL Server database. The managers here are going to have access to the PowerBi cloud, so I will end up uploading this to the cloud. There are 10 or so metrics that need to be shown on the dashboard. We have 5000+ employees. My first thought was to create a table and dump all the metrics into a table and set the PowerBi report to import the data, but that seems excessive and a waste of space to upload all that data to the CLOUD because all of the managers don't need access to every employee. They may want to see 1 or 2 employees' metrics on the dashboard.
My second thought is to (and if this is possible) create a stored procedure that will take the employee id and output a dataset for PowerBi to create a visual for. On the dashboard, have a list of employees and when a manager selects one, PowerBi will call the stored procedure with the employee id and the dataset will be returned for PowerBi to decipher into a visual based on my measurements. I guess I would set the PowerBi report connection type as DIRECT QUERY?
Here are my questions:
Is this possible? Is it possible to what I am thinking for my second plan? Is this how DIRECT QUERY works?
If so, how does DIRECT QUERY work with the PowerBi cloud?
What is setup like? Do I just install the PowerBi Data Gateway/configure it like IMPORT DATA and PowerBi does the rest?
A couple of queries:
What is the frequency of data update ?
In case if it is a batch job, it is ideally preferable to import that data from source into powerbi model and do reporting on the imported data as
a) The performance would be quicker
b) There would be no to and for of data across on prem database and cloud
c) the source would not be impacted constantly
So is the ask to have RLS wherein the managers should see only the employees under them?
Then it is pretty easy to implement RLS in imported version rather than in case of direct query.
Also you won't be able to pass parameters to stored procedures, and you can't execute them in direct query mode. You can however, create table valued functions which give you the ability to use table variables and perform other functions that are more complex in nature in Direct Query mode
you can refer this for additional details :
https://community.powerbi.com/t5/Desktop/Can-i-call-Stored-Procedure-with-Direct-Query/m-p/267141#:~:text=%40Pallavi%20you%20won't%20be,nature%20in%20Direct%20Query%20mode.

How to create a filter in powerbi that will dynamically query the db using a SP with a parameter

I am trying to run a direct query on my DB and apply a filter input by the user. The user input would be used as a parameter for my Stored Procedure that retrieves the data I want to display to the user. The reason for running a direct query and not just refreshing the data and then the user filtering from all of that data, is that the database is really large and it would make the report file approx. 650mb in size. My idea is that with a direct query, I can pull only the data required through an indexed column that the Stored Procedure uses to filter.
Currently I was able to create a parameter in the Query editor and use it in a query function but this creates an "Invoked Function" table. If I use these results in my report essentially the user can only filter through the result I filtered in my query editor. I want the user to be the one to input that value and the report to dynamically load it.
As far as the filter field, I am using a slicer and added the search capability to it so they can type out the search value and select the result in the list. Ideally I would like a textbox that they can type the value they want and search for it.
Is this possible in PowerBI? and if so how could I accomplish this?
You have to download a separate application called Power BI Report Builder to accomplish this and create a paginated report. See Url below:
Paginated Reports

programmatically change dataset SQL statement in power bi

Is it possible to change SQL statement of the dataset via API call?
My Scenario: I have data in multiple tables in SQL Server. I have created a SQL query with joins to fetch the required data. I created a SQL server dataset by providing that query in the SQL Statement section and published it on the Power BI workspace. Now, I want to modify that SQL Statment programmatically.
I want to import this same .pbix file to create different datasets. The Idea is to use import date set api to import this dummy dataset and then programmatically change the db source and the SQL Statment, to customizes it for my different report need.
Any pointer or help is much appreciated.
For server name and database name, you can simply use parameters. Click the button to the left of the field to do this. You can make some changes in the query using parameters too, but this isn't very flexible. This can be done by defining text parameter and using it in in the M statement associated with the dataset’s Source step. For more information you may see this article:
https://www.red-gate.com/simple-talk/sql/bi/power-bi-introduction-working-with-parameters-in-power-bi-desktop-part-4/
Then you can use the Rest API to modify parameter values and refresh your datasets. You will need Update Parameters In Group and Refresh Dataset In Group API calls.
At of this writing, this is not supported by the Power BI REST API.
Possible workaround: Given you're using SQL Server, I'd suggest you create a VIEW in SQL Server with the statement you defined in your Power BI report, and change your report to point to that view instead.
Then, to modify the SQL statement, you just have to ALTER the view in the database.