Dynamic cell range passed as SQL parameters in Power Query

Kazlik

Board Regular
Joined
Dec 9, 2014
Messages
68
I current have a working file with a table the users enters in a CategoryID that I then pass to a SQL query using Power Query. I would like to expand this for another use case but this time I want the user to enter in one or many rows of data and then pass all of the rows they enter into IN logic in my SQL.

//Current I use this
Team_parameter = Excel.CurrentWorkbook(){[Name="FullTextInputs"]}[Content],
SelectedCategoryID = Team_parameter[CategoryID]{0},
//And pass it into the SQL
team_id = " & Number.ToText(SelectedCategoryID) & "#(lf)

If I had a table like this what is the best way to get the 3 rows they entered comma separated.

Product
1
4
5


team_id IN ( " & Number.ToText(SelectedProduct) & ")
 

Excel Facts

Select a hidden cell
Somehide hide payroll data in column G? Press F5. Type G1. Enter. Look in formula bar while you arrow down through G.
Well the best way I can think of is to create 2 queries and then merge them inside power query and select the option to keep matching rows only.
 
Upvote 0
Hi Kazlik :-)
Try something like this (If I understood correctly your problem)
Code:
let
    Source = Excel.CurrentWorkbook(){[Name="tblParameters"]}[Content],
    Id = Text.Combine(Table.TransformColumnTypes(Source,{{"Product", type text}})[Product], ",")
in
    Id

Result will be "1,4,5".... Is that what you need?
 
Upvote 0
Hi Kazlik :-)
Try something like this (If I understood correctly your problem)
Code:
let
    Source = Excel.CurrentWorkbook(){[Name="tblParameters"]}[Content],
    Id = Text.Combine(Table.TransformColumnTypes(Source,{{"Product", type text}})[Product], ",")
in
    Id

Result will be "1,4,5".... Is that what you need?


Hello Gents,

I really liked the idea of having a range for Parameter. But in my case for some reason the query still filters for one parameter only. What is the best way for me to ensure I can get two or more line parameter to be passed to a query? thank you so much
 
Upvote 0

Forum statistics

Threads
1,226,195
Messages
6,189,571
Members
453,554
Latest member
Kate_

We've detected that you are using an adblocker.

We have a great community of people providing Excel help here, but the hosting costs are enormous. You can help keep this site running by allowing ads on MrExcel.com.
Allow Ads at MrExcel

Which adblocker are you using?

Disable AdBlock

Follow these easy steps to disable AdBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the icon in the browser’s toolbar.
2)Click on the "Pause on this site" option.
Go back

Disable AdBlock Plus

Follow these easy steps to disable AdBlock Plus

1)Click on the icon in the browser’s toolbar.
2)Click on the toggle to disable it for "mrexcel.com".
Go back

Disable uBlock Origin

Follow these easy steps to disable uBlock Origin

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back

Disable uBlock

Follow these easy steps to disable uBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back
Back
Top