This is really two parts: 1 on whether or not what I'm trying to do is a good approach, and 2 on how to do it.
For part 1, I have a variable list of units (changes based on what the user needs to check) for which I need to pull the status of each from an Oracle database. The most direct route seemed to be:
The problem is that the table I'm querying in Oracle is about 40 million rows, and attempting to merge the two queries takes so long that I eventually cancel out of it. Even though I might only want 5 rows, I'm assuming the approach above is forcing PQ to do the matching after pulling in the data, instead of letting the server handle it. As a comparison, when I write a simple query like SELECT unit, status FROM table WHERE unit IN (1, 2, 3, 4, 5), I get those results instantly.
My thought, then, is to create a dynamic variable to generate my IN list and feed that to the SQL in PQ, bypassing the need to merge two different queries. I was able to create the unit parameter so that I have a "query" in PQ that is nothing but my IN list, and then modify the query above like so:
This is where I hit part 2, the how. The syntax works fine (I checked it with a hard-coded parameter instead of from another query - success!), but this introduced me to the "Please rebuild this data combination" error Ken mentions here (excelguru.ca/blog/2015/03/11/power-query-errors-please-rebuild-this-data-combination). I don't know if what I'm trying to do is possible, or if I don't understand the blog post well enough to adapt it to this situation. I tried variations of the following but got the same error:
Any help is appreciated. Thanks!
For part 1, I have a variable list of units (changes based on what the user needs to check) for which I need to pull the status of each from an Oracle database. The most direct route seemed to be:
- Pull the user's list into PQ using From Table and create a connection only
- Query the Oracle database table with a connection only (SELECT unit, status FROM table)
- Merge the two queries based on the unit field to filter the values I get from the Oracle table
The problem is that the table I'm querying in Oracle is about 40 million rows, and attempting to merge the two queries takes so long that I eventually cancel out of it. Even though I might only want 5 rows, I'm assuming the approach above is forcing PQ to do the matching after pulling in the data, instead of letting the server handle it. As a comparison, when I write a simple query like SELECT unit, status FROM table WHERE unit IN (1, 2, 3, 4, 5), I get those results instantly.
Code:
let
Source = Oracle.Database("DATABASE", [Query="SELECT unit, status FROM table WHERE unit IN (1, 2, 3, 4, 5)"])
in
Source
My thought, then, is to create a dynamic variable to generate my IN list and feed that to the SQL in PQ, bypassing the need to merge two different queries. I was able to create the unit parameter so that I have a "query" in PQ that is nothing but my IN list, and then modify the query above like so:
Code:
let
Source = Oracle.Database("DATABASE", [Query="SELECT unit, status FROM table WHERE unit IN (" & UNIT_PARAM & ")"])
in
Source
This is where I hit part 2, the how. The syntax works fine (I checked it with a hard-coded parameter instead of from another query - success!), but this introduced me to the "Please rebuild this data combination" error Ken mentions here (excelguru.ca/blog/2015/03/11/power-query-errors-please-rebuild-this-data-combination). I don't know if what I'm trying to do is possible, or if I don't understand the blog post well enough to adapt it to this situation. I tried variations of the following but got the same error:
Code:
let
Source = UNITS_PARAM,
Query = Oracle.Database("DATABASE", [Query="SELECT unit, status FROM table WHERE unit IN (" & Source & ")"])
in
Query
Any help is appreciated. Thanks!