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

The Power BI Data Visualization World Championships is back! It's time to submit your entry. Live now!

Reply
Anonymous
Not applicable

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 @Anonymous ,

 

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.

Anonymous
Not applicable

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 @Anonymous ,

 

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
Power BI DataViz World Championships

Power BI Dataviz World Championships

The Power BI Data Visualization World Championships is back! It's time to submit your entry.

January Power BI Update Carousel

Power BI Monthly Update - January 2026

Check out the January 2026 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.