Forum Discussion
Need assistance to pull data dynamically using Emp Id in SQL query where clause to Power BI.
- 1 year ago
Hi Ubedulla,
Great to hear you are making progress thanks for sharing the screenshots, they really help clarify the setup.
From what you have described, it looks like the parameter and slicer are set up correctly, and you are already using Direct Query mode, which is perfect. However, if changing the slicer value isn’t updating the visual, it’s likely due to one key piece missing.
Binding the field to a parameter in the model is just the first step the real magic happens when you tell Power BI to filter the data using that parameter inside the query.Here is how you can do that:
- Go to Power Query Editor
- Locate your Fact_Internet_Sales table query
- Update the query so that it filters using the parameter, like this:
If you are using a custom SQL statement:
let CustomerKeyParam = Customer_Key_Parameter, Source = Sql.Database("YourServer", "AdventureWorksDW2019", [ Query = "SELECT * FROM FactInternetSales WHERE CustomerKey = " & Number.ToText(CustomerKeyParam) ]) in SourceOr, if you're using the default table navigation:
let Source = Sql.Database("YourServer", "AdventureWorksDW2019"), SalesTable = Source{[Schema="dbo", Item="FactInternetSales"]}[Data], FilteredRows = Table.SelectRows(SalesTable, each [CustomerKey] = Customer_Key_Parameter) in FilteredRows
Make sure the slicer is set to Single Select = ON. This is a known limitation: Multi-select is not supported when using slicers bound to parameters.
Once the query is correctly using the parameter in Power Query, you should see that changing the slicer value triggers a new SQL query and updates the table visual. Dynamic M query parameters in Power BI Desktop - Power BI | Microsoft Learn
Hope this helps clarify things and let me know what you find after giving these steps a try happy to help you investigate this further.
Thank you for using the Microsoft Community Forum.
Hi Ubedulla,
Great to hear you are making progress thanks for sharing the screenshots, they really help clarify the setup.
From what you have described, it looks like the parameter and slicer are set up correctly, and you are already using Direct Query mode, which is perfect. However, if changing the slicer value isn’t updating the visual, it’s likely due to one key piece missing.
Binding the field to a parameter in the model is just the first step the real magic happens when you tell Power BI to filter the data using that parameter inside the query.
Here is how you can do that:
- Go to Power Query Editor
- Locate your Fact_Internet_Sales table query
- Update the query so that it filters using the parameter, like this:
If you are using a custom SQL statement:
let
CustomerKeyParam = Customer_Key_Parameter,
Source = Sql.Database("YourServer", "AdventureWorksDW2019", [
Query = "SELECT * FROM FactInternetSales WHERE CustomerKey = " & Number.ToText(CustomerKeyParam)
])
in
Source
Or, if you're using the default table navigation:
let
Source = Sql.Database("YourServer", "AdventureWorksDW2019"),
SalesTable = Source{[Schema="dbo", Item="FactInternetSales"]}[Data],
FilteredRows = Table.SelectRows(SalesTable, each [CustomerKey] = Customer_Key_Parameter)
in
FilteredRows
Make sure the slicer is set to Single Select = ON. This is a known limitation: Multi-select is not supported when using slicers bound to parameters.
Once the query is correctly using the parameter in Power Query, you should see that changing the slicer value triggers a new SQL query and updates the table visual. Dynamic M query parameters in Power BI Desktop - Power BI | Microsoft Learn
Hope this helps clarify things and let me know what you find after giving these steps a try happy to help you investigate this further.
Thank you for using the Microsoft Community Forum.
Thank you soo much it is working...