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
Anonymous
Not applicable

Filtering a sql table on a list of values before import

Hi all, 

 

I have a > 30 millions records SQL table (stored in an Azure db). I would like to import only the 10k records whose ID can be found in another table that is already in my Power Bi data model. I import the external table with a query from the Transform Data menu:

 

 

 

 

my_external_table= Sql.Database(parameter_servername, parameter_dbname, [Query=" SELECT record_ID, text FROM external_table WHERE record_ID IN (...) " ])

 

 

 

I do not know how to properly write that WHERE clause. Is there a way to pass the column of my power bi table in the query? Like, let's say, saving it in a container of some sort?

In pure SQL a simple JOIN with the external table on the IDs of my power bi table would be enough, but I do not know how to achieve what I want without having to import all 30 millions records first.

 

 

EDIT: I also thought of creating a parameter with a list of values, the list being the whole column of my record_IDs. This way I should be abke to use it as argument for the IN clause. Still, if I go to Manage parameters -> New parameter -> Query the table where the list of IDs is does not show up in the dropdown menu. Of all the data model, only 4 tables appear.

1 ACCEPTED SOLUTION

Hi @Anonymous ,

 

Try a custom function and invoke it with a column that exists.

M code may like this:

(Year as number)as table=>
let 
    Source = Sql.Database("******", "test", [Query="SELECT *  FROM test_11#(lf) WHERE Year IN ("&Number.ToText(Year)&")", CreateNavigationProperties=false])
in
    Source

test_Filtering a sql table on a list of values before import2.PNG

When you invoke the query you will get a prompt asking for permission to run a native database query. This is a caution to warn you that some SQL is being run which could makes changes to the database.

This request for permission can be turned off. Click on File and then Options, and then Security.

test_Filtering a sql table on a list of values before import.PNG

 

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

View solution in original post

3 REPLIES 3
amitchandak
Super User
Super User

@Anonymous , You can write a choice of the query in Advance Property option, if it one time or refer

 

https://community.powerbi.com/t5/Desktop/parameterize-connection/m-p/205900#M90712

https://www.biinsight.com/power-bi-desktop-query-parameters-part-1/

 

AdvanceProperty.png

Full Power BI Video 20 Hours YouTube
Microsoft Fabric Series 60+ Videos YouTube
Microsoft Fabric Hindi End to End YouTube
Anonymous
Not applicable

hi @amitchandak , thanks for your help.

I am not sure I understand: if I create a parameter out of my list, I still need to assign it a value and, when I execute the query, the parameter has that value and will filter based on that value only. Am I getting something wrong?

In the advanced properties of the query, how should i write my query to include a list of values that is already in the data model?

 

edit: let me add that my list is 10k items long, so I cannot add it manually. I followed the procedure in one of the articles you linked (right click on the column -> add as new query -> use it to create a parameter) but I still have the problem that then I have to assign a single value to the parameter, so I cannot use it in the query.

Hi @Anonymous ,

 

Try a custom function and invoke it with a column that exists.

M code may like this:

(Year as number)as table=>
let 
    Source = Sql.Database("******", "test", [Query="SELECT *  FROM test_11#(lf) WHERE Year IN ("&Number.ToText(Year)&")", CreateNavigationProperties=false])
in
    Source

test_Filtering a sql table on a list of values before import2.PNG

When you invoke the query you will get a prompt asking for permission to run a native database query. This is a caution to warn you that some SQL is being run which could makes changes to the database.

This request for permission can be turned off. Click on File and then Options, and then Security.

test_Filtering a sql table on a list of values before import.PNG

 

Best Regards,
Liang
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.