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
Adam_Silva
New Member

Query SQL based on another table in power query.

Hello,

 

I'm try make a query, find by ID, this ID are in another table in power query, like this example bellow:

SELECT * FROM 123milhas.proc_estorno where id in( TABELA IDs.ID );

Can i do this ?

 

 

Query by another table.png

1 ACCEPTED SOLUTION
v-kelly-msft
Community Support
Community Support

Hi  @Adam_Silva ,

 

In query editor, click new Source>blank query:

vkellymsft_0-1631785098025.png

 

Then using below M codes:

= Table.SelectRows(#"Table",each List.Contains({6676856,7160339},[ID]))

And you will see:

vkellymsft_1-1631785140148.png

For the related .pbix file,pls see attached.

 

Best Regards,
Kelly

Did I answer your question? Mark my raeply as a solution!

View solution in original post

3 REPLIES 3
v-kelly-msft
Community Support
Community Support

Hi  @Adam_Silva ,

 

In query editor, click new Source>blank query:

vkellymsft_0-1631785098025.png

 

Then using below M codes:

= Table.SelectRows(#"Table",each List.Contains({6676856,7160339},[ID]))

And you will see:

vkellymsft_1-1631785140148.png

For the related .pbix file,pls see attached.

 

Best Regards,
Kelly

Did I answer your question? Mark my raeply as a solution!

watkinnc
Super User
Super User

Even easier than custom SQL is to just use the library function, and instead of IN, use List.Contains:

 

= Table.SelectRows(Table, each List.Contains(List.Buffer(#"Tabelas IDs"[ID]), [FactTableIDColumnName]))

 

That should fold, too.

 

--Nate 


I’m usually answering from my phone, which means the results are visualized only in my mind. You’ll need to use my answer to know that it works—but it will work!!
watkinnc
Super User
Super User

Yes. The easiest way is to make your "in" values into a list, then refer to the list. You should make the ID column type text, and then:


Add a new query named "items". 

 

= Text.Combine(List.Buffer(#"Tabela IDs"[ID]), ",")

 

Now you have a comma separated list named items.

 

Your IN statement would now be:

 

IN ("&items&")

 

As in, end your quote right where you need the list items inserted, &items&, and then start quotes again. 

--Nate

 


I’m usually answering from my phone, which means the results are visualized only in my mind. You’ll need to use my answer to know that it works—but it will work!!

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.

Top Solution Authors
Top Kudoed Authors