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

Earn the coveted Fabric Analytics Engineer certification. 100% off your exam for a limited time only!

Reply
pkoel-asb
Helper V
Helper V

New to Power BI - Trying to do a sub-query

Hello Friends,

 

I am trying to reproduce the following SQL Statement in the Query section of PowerBI Desktop:

 

select ProductPrice, Quantity from ShoppingCart

where OrderNumber in (select OrderNumber from Orders

  where DATEDIFF(day, OrderDate, GETDATE()) <= 365 and OrderFlag = 'C' and OrderSubtotal = 0

)

 

I can connect to the data source and see the tables. I have created the query (OTQ) for the Orders table, and generate the OrderNumbers. When I create the query (SCQ) for the ShoppingCart table I am unable to reference the values returned by the OTC query. I thought I should use a parameter in the SCQ query, but when I set the parameter to use the reults of an existing query; my OTC query does not show up in the querys list. Is that not the best way to accomplish a sub-query?

 

I apprecaite your advice.

 

Cheers,

 

Peter

1 ACCEPTED SOLUTION

HI @pkoel-asb ,

The simple way is copy 1st table t_sql query string and paste it to 2nd table sql statement and use them as sub-query.
In addition, you can extract 'table 1' fields and use text function to convert them as text string, then you can use these text string in 2nd sql statement as filter conditions.

Regards,

Xiaoxin Sheng

Community Support Team _ Xiaoxin
If this post helps, please consider accept as solution to help other members find it more quickly.

View solution in original post

3 REPLIES 3
v-shex-msft
Community Support
Community Support

Hi @pkoel-asb ,

Current you can't direct invoke t-sql query who created in other query table.
Maybe you can try to create a query parameter to store t-sql query then you can use it in other query table by invoke query parameter.

Regards,

Xiaoxin Sheng

Community Support Team _ Xiaoxin
If this post helps, please consider accept as solution to help other members find it more quickly.

Hello,

 

  How do I push the results of one query into a 2nd query?

 

Peter

HI @pkoel-asb ,

The simple way is copy 1st table t_sql query string and paste it to 2nd table sql statement and use them as sub-query.
In addition, you can extract 'table 1' fields and use text function to convert them as text string, then you can use these text string in 2nd sql statement as filter conditions.

Regards,

Xiaoxin Sheng

Community Support Team _ Xiaoxin
If this post helps, please consider accept as solution to help other members find it more quickly.

Helpful resources

Announcements
April AMA free

Microsoft Fabric AMA Livestream

Join us Tuesday, April 09, 9:00 – 10:00 AM PST for a live, expert-led Q&A session on all things Microsoft Fabric!

March Fabric Community Update

Fabric Community Update - March 2024

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