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

Register now to learn Fabric in free live sessions led by the best Microsoft experts. From Apr 16 to May 9, in English and Spanish.

Reply
claudiop
Employee
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
Memorable Member
Memorable Member

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
Microsoft Fabric Learn Together

Microsoft Fabric Learn Together

Covering the world! 9:00-10:30 AM Sydney, 4:00-5:30 PM CET (Paris/Berlin), 7:00-8:30 PM Mexico City

PBI_APRIL_CAROUSEL1

Power BI Monthly Update - April 2024

Check out the April 2024 Power BI update to learn about new features.

April Fabric Community Update

Fabric Community Update - April 2024

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