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

Join us at FabCon Atlanta from March 16 - 20, 2026, for the ultimate Fabric, Power BI, AI and SQL community-led event. Save $200 with code FABCOMM. Register now.

Reply
Anonymous
Not applicable

Using one query's results as filter (where clause) of next query

Want to use the results of query1 to database1, as a filter/where clause for query2 to database2 (and query 3 for database3 as well)

Getting query1 results into XLS/PQ is easy, but how do I feed that into query 2? Guessing pass it in as some sort of list so the end result in query2 is "where ID in (results1)?"

1 ACCEPTED SOLUTION
PhilipTreacy
Super User
Super User

Hi @Anonymous 

Download example PBIX file with these queries.

I don't know exactly what you are doing but let's say this is Query1

 

let
    Source = "clause one"
in
    Source

 

 

So it results in a string clause one

You can use this in Query2 like this

 

let
    Source = "where " & Query1
in
    Source

 

The result of Query2 being where clause one

And using this in Query3

 

let
    Source = "select * from table " & Query2
in
    Source

 

Resulting in select * from table where clause one 

 

I've just used strings as the result of each query but the same process applies if the query result is a table, a list, a record or whatever.

Regards

Phil


If I answered your question please mark my post as the solution.
If my answer helped solve your problem, give it a kudos by clicking on the Thumbs Up.



Did I answer your question? Then please mark my post as the solution.
If I helped you, click on the Thumbs Up to give Kudos.


Blog :: YouTube Channel :: Connect on Linkedin


Proud to be a Super User!


View solution in original post

4 REPLIES 4
PhilipTreacy
Super User
Super User

Hi @Anonymous 

Download example PBIX file with these queries.

I don't know exactly what you are doing but let's say this is Query1

 

let
    Source = "clause one"
in
    Source

 

 

So it results in a string clause one

You can use this in Query2 like this

 

let
    Source = "where " & Query1
in
    Source

 

The result of Query2 being where clause one

And using this in Query3

 

let
    Source = "select * from table " & Query2
in
    Source

 

Resulting in select * from table where clause one 

 

I've just used strings as the result of each query but the same process applies if the query result is a table, a list, a record or whatever.

Regards

Phil


If I answered your question please mark my post as the solution.
If my answer helped solve your problem, give it a kudos by clicking on the Thumbs Up.



Did I answer your question? Then please mark my post as the solution.
If I helped you, click on the Thumbs Up to give Kudos.


Blog :: YouTube Channel :: Connect on Linkedin


Proud to be a Super User!


Anonymous
Not applicable

Thanks Jimmy. I'm very new to this and couldn't google up any 'copy and paste' answers for what I'm trying to achieve. Can you help me with some example queries?

Hello @Anonymous 

 

then please describe what exaclty you need to achieve. @PhilipTreacy  gave you already some ideas how to handle, but there are so many ways out to do that. 

So waiting from a clear instruction what you need 🙂

 

BR

 

Jimmy

Jimmy801
Community Champion
Community Champion

Hello @Anonymous 

 

you can use the output of a query by just using the query name in your new query. For sure you have to pay attention on the output format of your query (if it's a text, list or a table). If you have a text, just include this text in you new query. Here probably the firewall will cick in 🙂

 

If this post helps or solves your problem, please mark it as solution (to help other users find useful content and to acknowledge the work of users that helped you)
Kudoes are nice too

Have fun

Jimmy

Helpful resources

Announcements
October Power BI Update Carousel

Power BI Monthly Update - October 2025

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

FabCon Atlanta 2026 carousel

FabCon Atlanta 2026

Join us at FabCon Atlanta, March 16-20, for the ultimate Fabric, Power BI, AI and SQL community-led event. Save $200 with code FABCOMM.

Top Kudoed Authors