Forum Discussion
More rows than filtered in Power query
- 6 years ago
I think the problem is the ODBC driver. I just connected to my SQL server via ODBC instead of directly and it does not support query folding in Power Query. So what that means is Power Query is importing your ENTIRE TABLE contents for each table you connect to, and then it works with everything in RAM. It is very inefficient, and little better than working with CSV files. In fact, it is probably about the same, except your tables are coming in structured and the ODBC driver is hopefully passing along data types and other relevant metadata.
But Power Query isn't generating nice neat SQL statements and sending it back for processing. That is assuming it is a relational database to begin with. It may not be, in which case no folding will happen regardless of connection type.
You can validate this though. Pull in 1 table. Do 1 simple filter. Right-click on that step. Does it say "View Native Query?" If that is grayed out, you aren't getting the advantage of a relational database connection. If it is, my whole theory on your speed issue is shot - other than I don't know what your ODBC driver is doing exactly and it could be doing a lot of interpretation and processing slowing things down.
I had an issue a few years ago I had to connect to an old SQL server (2000 I believe) that didn't support features required by Power Query so I had to pull in entire tables for Power Query to work with. It was on site, so processing about 4M records across about 10 tables and doing joins and what-not took 20-25min start to finish on a PC with 16GB of RAM to return 7,000 relevant records. Your record count is smaller, but I've no clue how many columns you have or the column content. Plus you said you were working remotely, so the transmission speeds wouldn't match what I was getting via ethernet.
If it is a relational database on the other end, and you cannot do a direct connection vs bypassing the ODBC driver, you could create a view on the server. You can see here what data sources Power BI supports natively (no need for ODBC). Sources like Amazon Redshift, IBM DB2, Oracle, SQL, SAP HANA, PostgreSQL, Vertica and many others support query folding. A view would let you apply filters and remove unnecessary columns, radically reducing data transmission times and local processing times.
Hi Edhan,
your reply helped me better understand my issue:
The data source is supported by the Power BI native query. I tested and it worked, I simply applied an SQL script in the data source settings and it imported only the rows that I filtered.
However when i apply "Filtered Rows" in Query Editor the "View native query" is greyed out when I right click on the Applied step!!
This means that the query folding will not take effect at this step in the server and therefore the hard work will be done by my desktop and of course more time is consumed.
Is there a solution to this?
Well, maybe.
If you typed something in the data source settings, NOTHING will fold after that. You are hardcoding the starting point.
What happens if you just connect to the data source, the database then a table? You should get two steps, a Source, and Navigation. If you right-click on Navigation and you can View Native Query, you should see something like this (This is the Person table in AdventureWorks2017.
select [$Table].[BusinessEntityID] as [BusinessEntityID],
[$Table].[PersonType] as [PersonType],
[$Table].[NameStyle] as [NameStyle],
[$Table].[Title] as [Title],
[$Table].[FirstName] as [FirstName],
[$Table].[MiddleName] as [MiddleName],
[$Table].[LastName] as [LastName],
[$Table].[Suffix] as [Suffix],
[$Table].[EmailPromotion] as [EmailPromotion],
[$Table].[AdditionalContactInfo] as [AdditionalContactInfo],
[$Table].[Demographics] as [Demographics],
[$Table].[rowguid] as [rowguid],
[$Table].[ModifiedDate] as [ModifiedDate]
from [Person].[Person] as [$Table]
At that point, you should be able to filter.
If you do not see View Native Query (grayed out) then it could be your data source and Power Query just doesn't understand how to create native statements for it.
If that is the case, then you just need to modify the advanced query when you are doing the connection to have your first step or two in the statement. This is filtering just for "EM" person type in the same table as above.
select [_].[BusinessEntityID],
[_].[PersonType],
[_].[NameStyle],
[_].[Title],
[_].[FirstName],
[_].[MiddleName],
[_].[LastName],
[_].[Suffix],
[_].[EmailPromotion],
[_].[AdditionalContactInfo],
[_].[Demographics],
[_].[rowguid],
[_].[ModifiedDate]
from [Person].[Person] as [_]
where [_].[PersonType] = 'EM'
That will prefilter your data. You can also eliminate columns here you don't need.
I've never seen an advanced statement work in the connection dialog but folding not work if you don't use an advanced statement, so I'd have to actually see your connection and play with it, which obviously isn't possible. It sounds like you just might have a data source that accepts a SQL statement, but not one that Power Query can generate, and it could be the ODBC driver being the issue. It may not be passing along enough info for PQ to know what it is, or it simply is a source PQ doesn't support for folding.
- aj19736 years agoCommunity Champion
The advanced query works fine with the ODBC Driver, the problem is that the report is built and deployed for a client and the report contains many tables so imagine the Hard coding that i have to go through..
In my Power query the 2 steps Source and Navigation are there for all tables but the problem is that i am able to see the code but i can't edit it in order to add some filters.
I just did another test using Filtered rows and connecting to another server. By elimination the problem is the ODBC Driver 32 Bits like you said " it could be the ODBC driver being the issue. It may not be passing along enough info for PQ to know what it is, or it simply is a source PQ doesn't support for folding."
I think Microsoft needs to find us a solution to this.