Skip to main content
cancel
Showing results for 
Search instead for 
Did you mean: 

Score big with last-minute savings on the final tickets to FabCon Vienna. Secure your discount

Reply
Que_Ry_Sa
New Member

How to pass selected Field Parameter to Query M SQL Query

Hi there

 

I have successfully used parameter binding on selected Values when the values are selected through a slicer on a 'hand-made' parameter table. The parameters are passed to the SQL query (direct query mode) where I insert the the bound parameter into the SQL-Query.

 

What I am trying to achieve now puzzles me: I have a FIELD PARAMETER slicer & table. Meaning I created a field parameter, where the user may select the column by which to visualize the bar chart. Let's say the values are Sales in $ and the columns to choose from are by Brand, Country or "Brand Partner Status". 

 

I am not able to pass the selected Column in the Field Parameter Slicer to the SQL query.

  • If I bind the ParamTable[Param Field] where the values are like 'NAMEOF('SalesTable'[BRAND]) then I get an error in my visualisation (something's wrong with the column...). 
  • When I try to select the ParamTable[Param] Column (first column of the generated table) or the ParamTable[Param Order] then I just always get the standard parameter value as result.
  • When I try to filter a second 'hand made' table called SELECTEDCOLUMN with the same options according to the slicer using a relationship and try to use QueryM-Function Table.FirstValue(), then I just get the first value of the table SELECTEDCOLUMN without the applied filtering in the UI

 

Does anybody know how to achieve this?

1 ACCEPTED SOLUTION
rohit1991
Super User
Super User

Hi @Que_Ry_Sa 


Passing a dynamic Field Parameter to a native SQL query isn't straightforward because SQL expects fixed column references, while Field Parameters are evaluated at runtime on the Power BI side.

Unfortunately, Field Parameters can't directly influence the structure of a SQL query, because M/Power Query (and SQL behind it) doesn't interpret dynamic column names from slicers or field parameters the way a DAX visual would.

Here’s a possible approach you can try (I've used this successfully in similar setups):

  1. Create a parameterized SQL view in your SQL Server (or underlying source). This view takes a string input for the column name and applies a CASE or dynamic SQL inside the view logic itself.
  2. In Power BI:
    • Keep using your Field Parameter slicer to let users pick the column.
    • Create a mapping table that translates your slicer choices (e.g., "Brand", "Country") into the actual SQL-safe column names.
    • Use a disconnected table and capture the selected column using a measure like:
SelectedCol = SELECTEDVALUE(ParamTable[Param Field])
  1. Pass that value into a M parameter using Power Query (this requires breaking query folding and turning it into a native query), like:
SELECT
 CASE WHEN @SelectedColumn = 'Brand' THEN Brand
      WHEN @SelectedColumn = 'Country' THEN Country
      WHEN @SelectedColumn = 'PartnerStatus' THEN [Brand Partner Status]
 END AS DynamicColumn
FROM SalesTable
  1. Connect your slicer to the parameter via a what-if parameter or use Table.FirstValue() carefully with a properly filtered table not the field parameter table.

Did it work? ✔ Give a Kudo • Mark as Solution – help others too!

View solution in original post

5 REPLIES 5
v-sdhruv
Community Support
Community Support

Hi @Que_Ry_Sa ,
Since we didnt hear back, we would be closing this thread.
If you need any assistance, feel free to reach out by creating a new post.

Thank you for using Microsoft Community Forum

v-sdhruv
Community Support
Community Support

Hi @Que_Ry_Sa ,

Just wanted to check if you got a chance to review the suggestions provided and whether that helped you resolve your query?


Thank You

v-sdhruv
Community Support
Community Support

Hi @Que_Ry_Sa ,

Just wanted to check if you got a achance to review the suggestions provided and whether that helped you resolve your query?

Thank You

danextian
Super User
Super User

Selected values from field parameters can't be passed into M SQL queries. While M influences the semantic model, anything done in the report designer stays within the designer - it doesn't flow back into the query layer. Only parameter values in the query editor can be passed on to a M SQL query.





Dane Belarmino | Microsoft MVP | Proud to be a Super User!

Did I answer your question? Mark my post as a solution!


"Tell me and I’ll forget; show me and I may remember; involve me and I’ll understand."
Need Power BI consultation, get in touch with me on LinkedIn or hire me on UpWork.
Learn with me on YouTube @DAXJutsu or follow my page on Facebook @DAXJutsuPBI.
rohit1991
Super User
Super User

Hi @Que_Ry_Sa 


Passing a dynamic Field Parameter to a native SQL query isn't straightforward because SQL expects fixed column references, while Field Parameters are evaluated at runtime on the Power BI side.

Unfortunately, Field Parameters can't directly influence the structure of a SQL query, because M/Power Query (and SQL behind it) doesn't interpret dynamic column names from slicers or field parameters the way a DAX visual would.

Here’s a possible approach you can try (I've used this successfully in similar setups):

  1. Create a parameterized SQL view in your SQL Server (or underlying source). This view takes a string input for the column name and applies a CASE or dynamic SQL inside the view logic itself.
  2. In Power BI:
    • Keep using your Field Parameter slicer to let users pick the column.
    • Create a mapping table that translates your slicer choices (e.g., "Brand", "Country") into the actual SQL-safe column names.
    • Use a disconnected table and capture the selected column using a measure like:
SelectedCol = SELECTEDVALUE(ParamTable[Param Field])
  1. Pass that value into a M parameter using Power Query (this requires breaking query folding and turning it into a native query), like:
SELECT
 CASE WHEN @SelectedColumn = 'Brand' THEN Brand
      WHEN @SelectedColumn = 'Country' THEN Country
      WHEN @SelectedColumn = 'PartnerStatus' THEN [Brand Partner Status]
 END AS DynamicColumn
FROM SalesTable
  1. Connect your slicer to the parameter via a what-if parameter or use Table.FirstValue() carefully with a properly filtered table not the field parameter table.

Did it work? ✔ Give a Kudo • Mark as Solution – help others too!

Helpful resources

Announcements
August Power BI Update Carousel

Power BI Monthly Update - August 2025

Check out the August 2025 Power BI update to learn about new features.

August 2025 community update carousel

Fabric Community Update - August 2025

Find out what's new and trending in the Fabric community.

Top Solution Authors