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

Next up in the FabCon + SQLCon recap series: The roadmap for Microsoft SQL and Maximizing Developer experiences in Fabric. All sessions are available on-demand after the live show. Register now

Reply
NancySharma
Regular Visitor

Way to query data using SQL and csv file

I want to query my sql database based on some fields in csv file. 

 

When i connect to query can i use the query to connect this way for example.

 

SELECT Column1

      ,Column2

      ,Column3

FROM myDB1.TableName OU

WHERE OU.Column1 IN (

SELECT id FROM  Source = Csv.Document

WHERE CSVColumnName IN (“product”, “abc”));

 

11 REPLIES 11
Phil_Seamark
Microsoft Employee
Microsoft Employee

Hi @NancySharma

 

I wrote a blog explaining one technique you can use in Power Query to generate dynamic SQL

 

http://radacad.com/dynamic-sql-using-power-query

 

 


To learn more about DAX visit : aka.ms/practicalDAX

Proud to be a Datanaut!

Hi Phil,

 

I am new to Power BI,

 

What i see is that you made changes to data on Power BI. What i want is that i get prefiltered data from sql based on filter in CSV file so that only needed data gets loaded in power BI.

 

Reason is when i try to form joins and filter data in power BI, it takes a lot of time when i refresh my CSV file, it has like million records. So what i am looking for is  i get prefiltered data uploaded to BI based on CSV filer that i can put in query.

Hi @NancySharma

 

All the work should be done in Power Query (which sits before Power BI).  You can query your CSV file and you will have to read all of it.  Then in Power Query, you can generate a list values from the CSV file that you are interested in and finally use that list inside your T-SQL query statement in the WHERE clause.


To learn more about DAX visit : aka.ms/practicalDAX

Proud to be a Datanaut!

Yes  i tried this approach but apparently when i refresh my csv file this query stops working. Is there a workaround for that or any other solution.

Hi @NancySharma

 

It shouldn't stop.  Power Query should be smart enough to know that it needs to fully load the CSV table to generate the list you need for your SQL data source.  If you click the view dependances button on the PQ ribbon you should see a diagram showing the flow of the logic. 

 

I think something else might be causing an issue. 


To learn more about DAX visit : aka.ms/practicalDAX

Proud to be a Datanaut!

It does not work when i move Power BI File  from one user to another. am i doing something wrong?

Hi @NancySharma

 

I'm not sure what you mean by "moving from one user to another"


To learn more about DAX visit : aka.ms/practicalDAX

Proud to be a Datanaut!

so once i ma able to join the databases and able to design the report the way i want. i save it as Microsoft Power BI Desktop Template (.pbit) and send the same to other users. But wen they open is template and try to run the report by refreshing it does not work.

Anonymous
Not applicable

@NancySharma,

What error message do your users get?  Could you please also post the codes in your Advanced Editor? Do mask sensitive data before uploading codes.

Regards,
Lydia

It does not work when i move Power BI File  from one user to another

Yes  i tried this approach but apparently when i refresh my csv file this query stops working. Is there a workaround for that or any other solution.

Helpful resources

Announcements
New to Fabric survey Carousel

New to Fabric Survey

If you have recently started exploring Fabric, we'd love to hear how it's going. Your feedback can help with product improvements.

Power BI DataViz World Championships carousel

Power BI DataViz World Championships - June 2026

A new Power BI DataViz World Championship is coming this June! Don't miss out on submitting your entry.

Join our Fabric User Panel

Join our Fabric User Panel

Share feedback directly with Fabric product managers, participate in targeted research studies and influence the Fabric roadmap.

March Power BI Update Carousel

Power BI Community Update - March 2026

Check out the March 2026 Power BI update to learn about new features.