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

The Power BI Data Visualization World Championships is back! Get ahead of the game and start preparing now! Learn more

Reply
Anonymous
Not applicable

Merge Querry - efficiency

I have an SQL table that more than 400 Million rows and I only need about 200 thousand. I thought I could inner merge the querries based on project number to only pull the 200k rows. But it seems as though it is still pulling the 400M rows and then trys to merge them.

 

Obviously this is a wasting a huge amount of time and processing power. Is there a better way to do this?

1 ACCEPTED SOLUTION
RandyPgh
Resolver III
Resolver III

I'm assuming that your SQL table means SQL Server. For this either you or your DBA should write a query with WHERE conditions to restrict the data being returned. Better yet, a stored procedure or view could be used. However you do it, you enter the query in this way.

 

1. Click Get Data.

2. Choose SQL Server.

3. Enter your Server and Database names.

4. Choose Import or DirectQuery.

5. Under the DirectQuery radiobutton, click the "Advanced options" item to open several additional options.

6. Enter your query or stored procedure statement in the "SQL statement" box.

 

If you want to go the route of a stored procedure, there are probably several articles about using one with Power BI. Here is one.

 

View solution in original post

3 REPLIES 3
SteveCampbell
Memorable Member
Memorable Member

Depending on your data source. Read up on query folding (https://exceleratorbi.com.au/how-query-folding-works/). You are able to push this back to the data source to let it do the work, but check your steps and data source as described in the article, here's some important points:

  1. The source must be a database that can accept a folding request.  Most relational databases are included.  It can also be an OData source, SSAS and Google Analytics (thanks Miguel and Chris).
  2. If you start your query with SQL code you wrote yourself, no further steps inside Power Query will be folded.
  3. Once you perform a step that cannot be folded, query folding stops for the rest of the query.

 

To check it is still working, you can right click on the applied step and see if you are able to select "View native query".

 

Try to load the raw data, do the merge, then apply other steps first.

 

Appreciate your Kudos
Connect with me!

Stay up to date on  linkedin-logo.png
Read my blogs on  powerbi.tips_.png



Did I answer your question? Mark my post as a solution! Proud to be a Super User!


Connect with me!
Stay up to date on  
Read my blogs on  



Anonymous
Not applicable

Thanks, both your answers helped me resolve my issue. This really opens my eyes to many new possibilities

RandyPgh
Resolver III
Resolver III

I'm assuming that your SQL table means SQL Server. For this either you or your DBA should write a query with WHERE conditions to restrict the data being returned. Better yet, a stored procedure or view could be used. However you do it, you enter the query in this way.

 

1. Click Get Data.

2. Choose SQL Server.

3. Enter your Server and Database names.

4. Choose Import or DirectQuery.

5. Under the DirectQuery radiobutton, click the "Advanced options" item to open several additional options.

6. Enter your query or stored procedure statement in the "SQL statement" box.

 

If you want to go the route of a stored procedure, there are probably several articles about using one with Power BI. Here is one.

 

Helpful resources

Announcements
Power BI DataViz World Championships

Power BI Dataviz World Championships

The Power BI Data Visualization World Championships is back! Get ahead of the game and start preparing now!

December 2025 Power BI Update Carousel

Power BI Monthly Update - December 2025

Check out the December 2025 Power BI Holiday Recap!

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.