The ultimate Fabric, Power BI, SQL, and AI community-led learning event. Save €200 with code FABCOMM.
Get registeredCompete to become Power BI Data Viz World Champion! First round ends August 18th. Get started.
I am working to convert a lot of SSRS reports to Power BI. Most I have been able to use the existing SQL logic from SSRS. For my current issue I have a lengthy SQL statement that is used to create an SSRS report that I want to use in Power BI. I had to delete most of the logic to get it to fit in the message below. These statements are positioned in various spots througout the logic. The problem I am having is that the SQL statements below references a start, end, and a delivery date which is based on the DECLARE start and end date. that is selected in the SSRS report. I have a date between slicer in the Power BI dashboard I want to use, but I am not sure if a SQL statement can be written to reference a slicer in place of the these date statements so the logic works in Power BI . Any suggestions or tips would be greatly appreciated. Thanks.
Solved! Go to Solution.
Hi @cheid_4838
Here's a concise action plan to reference a slicer in SQL queries within Power BI, which will allow you to dynamically filter your data based on slicer selections:
Create Dynamic M Query Parameters: In Power BI Desktop, navigate to Home > Transform data > Transform data to open the Power Query Editor. Use the Manage Parameters option to create new parameters that will represent your start and end dates. For detailed guidance, please refer to :Dynamic M query parameters in Power BI Desktop - Power BI | Microsoft Learn .
Reference the Parameters in Your SQL Query: Modify your SQL query within the Power Query Editor to reference the created parameters for start and end dates. Instead of using statements, you'll pass these parameters directly into your query where needed.
Bind the Parameters to Slicer Values: To ensure the slicer controls the parameters, you'll need to create a table of date values in Power BI and bind these to your parameters. This step is crucial for allowing slicer selections to dynamically update your SQL query.
Best Regards,
Jayleny
If this post helps, then please consider Accept it as the solution to help the other members find it more quickly.
Hi @cheid_4838
Here's a concise action plan to reference a slicer in SQL queries within Power BI, which will allow you to dynamically filter your data based on slicer selections:
Create Dynamic M Query Parameters: In Power BI Desktop, navigate to Home > Transform data > Transform data to open the Power Query Editor. Use the Manage Parameters option to create new parameters that will represent your start and end dates. For detailed guidance, please refer to :Dynamic M query parameters in Power BI Desktop - Power BI | Microsoft Learn .
Reference the Parameters in Your SQL Query: Modify your SQL query within the Power Query Editor to reference the created parameters for start and end dates. Instead of using statements, you'll pass these parameters directly into your query where needed.
Bind the Parameters to Slicer Values: To ensure the slicer controls the parameters, you'll need to create a table of date values in Power BI and bind these to your parameters. This step is crucial for allowing slicer selections to dynamically update your SQL query.
Best Regards,
Jayleny
If this post helps, then please consider Accept it as the solution to help the other members find it more quickly.