cancel
Showing results for 
Search instead for 
Did you mean: 
Reply
schdef Frequent Visitor
Frequent Visitor

Parameterized SQL Query with query folding

I have a table loaded to my data model containing IDs. I want use these IDs to filter another query connecting to a SQL table. I tried to merge the SQL query with the ID table but then the query does not get folded as it should (which is a problem as my SQL source has millions of rows). Any practice that makes sense thinking of performance in particular... Thxs much!!

1 ACCEPTED SOLUTION

Accepted Solutions
Community Support Team
Community Support Team

Re: Parameterized SQL Query with query folding

Hi @schdef,

 

You can tansfrom your data to text, then use it into sql query.

 

Sample: Convert region records to text.

 

let
    Source=data,
    Region = "'"&Text.Combine(List.Distinct(Source[Region]),"','")&"'"
in
    Region

 

Capture.PNGCapture2.PNG

 

Insert into sql query:

 

let
Source = Sql.Database("xxxxx", "xxxxx", [Query="SELECT * FROM Sales WHERE Region In ("&Region&")"])
in
Source

 

 

Regards,

Xiaoxin Sheng

Community Support Team _ Xiaoxin Sheng
If this post helps, please consider Accept it as the solution to help the other members find it more quickly
Learning resources: Power BI

View solution in original post

4 REPLIES 4
Community Support Team
Community Support Team

Re: Parameterized SQL Query with query folding

Hi @schdef,

 

You can tansfrom your data to text, then use it into sql query.

 

Sample: Convert region records to text.

 

let
    Source=data,
    Region = "'"&Text.Combine(List.Distinct(Source[Region]),"','")&"'"
in
    Region

 

Capture.PNGCapture2.PNG

 

Insert into sql query:

 

let
Source = Sql.Database("xxxxx", "xxxxx", [Query="SELECT * FROM Sales WHERE Region In ("&Region&")"])
in
Source

 

 

Regards,

Xiaoxin Sheng

Community Support Team _ Xiaoxin Sheng
If this post helps, please consider Accept it as the solution to help the other members find it more quickly
Learning resources: Power BI

View solution in original post

schdef Frequent Visitor
Frequent Visitor

Re: Parameterized SQL Query with query folding

Thanks Xiaoxin! Was hoping to get this adressed with query folding and applying filters dynamically but your solution works as well.

bkellner Occasional Visitor
Occasional Visitor

Re: Parameterized SQL Query with query folding

I am working in Excel Power Pivot, my parameter list is generated from a table in the worksheet. The list generates well, and it displays correctly in the Query that is supposed to go out to SQL. Everything looks good, except, I am running into  a Formula.Firewall error message complaining that my step 'Source' references other queries and I need to rebuild it.

 

For months, I have been trying to figure out a way to fold dynamic parameters back to SQL. This is the closest I have gotten. I can see how this should work. I can't get around the error message though.

 

Is there something I need to be aware of when connecting to the database? Has something changed in the software that prevents this from folding back as intended? Are there better ways today to accomplish this task?

Vinith_Joel_swi Frequent Visitor
Frequent Visitor

Re: Parameterized SQL Query with query folding

Even i have same error refelecting ? I couldnt find solution for that . Is there anyother way to do it ?

Helpful resources

Announcements
Exclusive LIVE Community Event #3 – Ask Arun Anything

Exclusive LIVE Community Event #3 – Ask Arun Anything

Join us in the third Triple A event!

Meet the 2020 Season 1 Power BI Super Users!

Meet the 2020 Season 1 Power BI Super Users!

It’s the start of a new Super User season! Learn all about the new Super Users and brand-new tiered recognition system.

Super User Challenge: Can You Solve These?

Super User Challenge: Can You Solve These?

We're celebrating the start of the New Super User season with our first ever Super User 'Can You Solve These?' challenge.

Power BI Desktop Update - February 2020

Power BI Desktop Update - February 2020

We are super excited for our update this month, as we are releasing two of our top community requests!

Power Platform Online Conference

Power Platform Online Conference

Join us for the first ever Power Platform Online Conference!

Top Solution Authors