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

Compete to become Power BI Data Viz World Champion! First round ends August 18th. Get started.

Reply
ikkew
Advocate I
Advocate I

Querry SQL View or Procedure with dynamic parameter

I'm still struggling with some of the PowerBI basics, so don't be surprised if I'm trying to do things in a weird or unorthodox way. Yet i need to move forward and I'm really trying my best. Any sort of help, advice or solutions to the problem are appreciated. As a disclaimer, I know Direct Querrying exists but I can't seem to make it useful in my case.

 

I'm currently trying to load in a view or procedure that should have a dynamic paramter for it's where statement. This parameter shouldn't be decided upon connecting to the DB source but rather upon selecting an article in a table. Actually, this is just the way I'm trying to make stuff work since I can't think of another way for it to work, so the solution might be for me to redo the whole thing in another way.

 

My case is as followed: I have customers who buy articles with different distributors. I know which price they pay per article but the same article could be bought with another distributor for a different price. I'm trying to figure out the minimum or maximum paid price, which I made work bu using some scalar-valued functions. However, now I'm comparing every customer, yet some fall in a different category. For example, we have the customer type (hotel) and the customer size (big). I need to make sure I only compare big hotels and therefore the only solution I can think of is to edit my views/procedures with a where statement. Again, I can only know which where-statement should be taken upon selecting an article (which falls under a customer)

 

As an example, this is what I was able to cook up so far (Can't seem to upload images):
https://i.imgur.com/K9a5wm5.png

 

Off course, the above case isn't the only one I'm struggling with. For example, same goes for getting the top 50 articles for a customer (I do this with a view, which needs the customer parameter). I've been searching the web and I've found and tried functions like TOPN and RANKX but still can't get it to work... and yes, the list goes on and I feel lost

2 REPLIES 2
v-chuncz-msft
Community Support
Community Support

@ikkew,

 

It seems that you may just use Subqueries.

Community Support Team _ Sam Zha
If this post helps, then please consider Accept it as the solution to help the other members find it more quickly.

Thank you for taking the time to read over and answer the question. However, I don't see the option to use a dynamic paramter (chosen from the visual) in the subquery. How would one do this?

 

After searching some more and taking your suggestion in consideration, I managed to follow this link: https://community.powerbi.com/t5/Desktop/Subquery/m-p/319059/highlight/true#M141971 to https://www.sqlbi.com/articles/from-sql-to-dax-filtering-data/ where it would seem that I can use a filter to devide my customers in categories. However, some way of dynamically adding a parameter (to filter) seems nescecary in my case.

 

I've been able to add parameters with functions, yet can't do this with views or procedures.

 

Maybe I'm just having trouble understanding the concept..

 

Or maybe some sort of DAX function where I translate my procedure/view into DAX, which will enable me to use my slicers without the need of dynamic parameters.

Helpful resources

Announcements
July 2025 community update carousel

Fabric Community Update - July 2025

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

July PBI25 Carousel

Power BI Monthly Update - July 2025

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