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

Don't miss out! 2025 Microsoft Fabric Community Conference, March 31 - April 2, Las Vegas, Nevada. Use code MSCUST for a $150 discount. Prices go up February 11th. Register now.

Reply
claudiop
Microsoft Employee
Microsoft Employee

table with id(int), and name(string), slicer shows names, how to bind param to corresponding id?

I have:

1. A query that returns a table with two columns: ItemId (int), and ItemName (string). Table contains multiple rows.

2. A Slicer showing Items' names, for users to select one or more items by name from the list.

3. A PowerBI parameter bound to the ItemName (string)

 

I use that parameter to query SQL Server (Direct Query), using the names selected by the user in the slicer in my SQL query.

And that works 'ok.'

 

However, what I would really like to do is pass the Item IDs (INT) of the items selected by the user in the slicer, instead of Item Names. 

 

Would that be doable? How?

 

I have tried many things but nothing worked.

 

For instance, tried, 

   let ItemId = MyTable[ItemId]{List.PositionOf(MyTable[ItemName], ItemNameParameter, 0)},

 

...and then I tried using that ItemId in my query,

 Source = Sql.Database(SqlServerParameter, SqlDatabaseParameter, [Query=FilterQuery])

 

But PowerBI's Firewall complianed with an error like:

 "Formula.Firewall: Query 'Blah' (step 'Source') references other queries or steps, so it may not directly access a data source. Please rebuild this data combination."

 

and I could not figure out how to resolve that.

 

Alternatively: is there any way for a query to reference a parameter bound to another query? 

 

Thanks,

Claudio

 

4 REPLIES 4
vojtechsima
Super User
Super User

Hello, @claudiop 

should be fairly easy.

See screenshot here, I am slicing through "Product" which is complete nonsense but then actually filtering by associated ID.

 

vojtechsima_0-1697304283596.png

This is my slicer table:

vojtechsima_1-1697304302547.png

If you have trouble with Privacy levels, either align them, so they are the same or ignore them:

vojtechsima_2-1697304368094.png

or in settings like this:

vojtechsima_3-1697304392594.png

Then the actually query look like this:

 

vojtechsima_5-1697304885526.png

 

 

 selectedItem = Table.SelectRows(listForParam, each item = [Product]){0}[id],
  

 

here, this variable prepares the selected item, so it seraches the "slicer table" takes the selected Value, and then takes first row  ({0}) from column ID ([id]) and that variable is then used in the SQL itself.

Thanks vojtechsima for your response. I tried doing that with Direct Query, but getting the below errors:

 

Formula.Firewall: Query 'ImportedQueryCount' (step 'Source') references other queries or steps, so it may not directly access a data source. Please rebuild this data combination.

 

Tried ignoring privacy and making other changes, but got this: 

 

Failed to save modifications to the server. Error returned: 'DirectQuery partition 'ImportedQueryCount-ee454ffe-0c4b-4df0-9e76-c5c0db92c1cd' has '2' datasource reference(s) in its expression which is not allowed.

 

Any ideas?

 

 

@claudiop ,

well, perhaps the workaround is to create manual input of the filtering data, or it should be two compatible sources.

Normally, I would say, just write it as a function and call it insnide the main query, but you need a physical table for the slicer. So right now I don'T have any other solution.

Thanks vojtechsima -- I greatly appreciate your detailed responses.  I will keep looking for a solution, and will update this thread if I find one.

 

Thank you.

Claudio

 

Helpful resources

Announcements
Las Vegas 2025

Join us at the Microsoft Fabric Community Conference

March 31 - April 2, 2025, in Las Vegas, Nevada. Use code MSCUST for a $150 discount! Prices go up Feb. 11th.

Jan25PBI_Carousel

Power BI Monthly Update - January 2025

Check out the January 2025 Power BI update to learn about new features in Reporting, Modeling, and Data Connectivity.

Jan NL Carousel

Fabric Community Update - January 2025

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