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
Anonymous
Not applicable

Use list of values as input to SQL query

Hi,

 

I have a list of databases that is generated from a SQL query:

let
    Source = Sql.Database(Server, "master", [Query="SELECT name FROM master.dbo.sysdatabases"])
in
    Source

The list is then set to use a slicer and a search bar

I would then like to have other SQL queries to run and use the database name I select in my first list as an input value but cant make it work.

 

I have created a query list based upon the list of databases (then name of the query list i dbQueryList) and have a parameter called database with the type: text, Suggested Values: Query and I have then pointed out the list that is called "dbQueryList"

 

Now I want to have one of the selected database names as an input and run query like this one:

select count(*) from custom_table where status <>'Error'

How can I use the selected value from my first list and then have the query result updated based upon the name of the database?

 

2 REPLIES 2
JosefPrakljacic
Solution Sage
Solution Sage

Hey @Anonymous ,

 

here is a helpful blog article. The principle is the same I would say.

 

https://www.biinsight.com/power-bi-desktop-query-parameters-part2-dynamic-data-masking-and-query-parameters/

 

If this post was helpful may I ask you to mark it as solution and give it a 'thumbs up'? This will also help others

Have a nice day!

BR,
Josef
Graz - Austria

Anonymous
Not applicable

Thanks for your reply. 

The have problems when I try to authenticate against the server when I try to replace the value of the database name and instead point towards the list of databases

 

The query looks like this:

let
    Source = Sql.Database(Server, "&dbQueryList&", [Query="select count (*),  datepart (day, completed) as day,datepart (hour, completed) as hr from ChannelMessageHistory#(lf)where completed >= getdate()-1#(lf)group by datepart (day, completed), datepart (hour, completed)--, method#(lf)order by datepart (day, completed), datepart (hour, completed)--, method#(lf)"])
in
    Source

It will then try to login to an database with the name of "&dbQueryList&" which off cource doesnt work. How do I write the query to reference back to the list?

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.