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

Join us for an expert-led overview of the tools and concepts you'll need to become a Certified Power BI Data Analyst and pass exam PL-300. Register now.

Reply
MathewT
Microsoft Employee
Microsoft Employee

Question: Get Data Advanced SQL Statement using existing PowerBI field

Greetings!  I want to filter rows I'm bringing into Power BI Desktop using the advanced option sql query and referencing an already-created field as part of that query. 

 

If my large database to import/filter has a table called NewTable and I have a table already in PowerBI called SmallTable and both contain a field called CommonID, how do I write the query to Select/Import only rows from NewTable where NewTable[CommonID] is also in SmallTable[CommonID].   I can't seem to find the right syntax to enable Power BI Desktop to reference SmallTable. 

3 REPLIES 3
v-yadongf-msft
Community Support
Community Support

 

Hi @MathewT ,

 

This is Table1:

vyadongfmsft_6-1665731632300.png

 

This is Table2:

vyadongfmsft_7-1665731632301.png

 

Table1 has connected to Power BI by Direct Query mode.

vyadongfmsft_8-1665731632301.png

 

Please try:

SELECT Table2.* FROM Table2 INNER JOIN Table1 ON Table2.ID = Table1.ID

vyadongfmsft_9-1665731632302.png

 

 

I think this is the result you want:

vyadongfmsft_10-1665731632303.png

Best regards,

Yadong Fang

If this post helps, then please consider Accept it as the solution to help the other members find it more quickly.

Thanks for your response. Table1 is part of the SQL database being read in. Table2 is a table ALREADY in PowerBI. The probem is PowerBI is not recognizing the Table2 reference.

Hi @MathewT ,

 

On my test, Table 1 is a table already in Power BI. Table 2 is part of the SQL database being read in. 

Please check again.

 

Best regards,

Yadong Fang

If this post helps, then please consider Accept it as the solution to help the other members find it more quickly.

Helpful resources

Announcements
Join our Fabric User Panel

Join our Fabric User Panel

This is your chance to engage directly with the engineering team behind Fabric and Power BI. Share your experiences and shape the future.

June 2025 Power BI Update Carousel

Power BI Monthly Update - June 2025

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

June 2025 community update carousel

Fabric Community Update - June 2025

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