Forum Discussion
Dynamic SQL Query with Parameters from URL
- Anonymous2 years ago
Hi bmanahan ,
May I ask if this is the Power Bi paramater you are referring to:If yes, then your needs cannot be realized. The Power BI parameter and the Power Query parameter are two different things and there is no way they can be linked together. And Power BI parameter can not be used to create a dynamic SQL query.
You can achieve a similar effect by using DirectQuery and dynamic M query parameters to control your SQL query based on slicer or filter selections in your report:
Bind this table's field to a Power Query parameter as described in this documentation. This allows the selection in a slicer or filter to dynamically adjust the query parameter.
Use a slicer in your report for distributors to select the distributor ID, which then dynamically adjusts the SQL query through the bound parameter.
While this approach does not directly use the URL parameter to adjust the Power Query parameter, it provides a way to dynamically control the data being queried based on user interaction with the report.
As an alternative, consider using Power Automate to trigger your SQL queries with the distributor ID as an input parameter. Power Automate can then process the data as needed and push the results into a Power BI dataset. Use Power Automate to create a flow that triggers the extraction process. You can set the flow to run on a schedule or to be triggered by an event. Within the flow, use the SQL Server connector to execute SQL queries that extract the necessary data based on the distributor ID. You can pass the distributor ID as a parameter to the SQL query to retrieve distributor-specific data.
Best Regards,
Dino Tao
If this post helps, then please consider Accept it as the solution to help the other members find it more quickly.
Much close now, but I still have issues. I created a new query to pull in all the distributor ids, I think used the method in the video from the link to bind the paramater. So I am now set the paramater for my query when I filter the my data on the distributor id table (table name Dist_id, column name Dist_ID). This is all great.
Now my issue is that I cannot set the filter though a URL. I tried setting the fitler by add the following at the end of the end of the embded URL, but nothing appears to be fitlering. &filter=dist_id/dist_id%20eq%201121
Any ideas on what is wrong to get my filter to work?
I think I found my problem with the URL string. It is case sensitive. Once I fixed that it is working.