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

Enhance your career with this limited time 50% discount on Fabric and Power BI exams. Ends August 31st. Request your voucher.

Reply
domtrump
Helper II
Helper II

Pass parameter from Cell(s)

Is there some way to pass a parameter to PQ from a value in a cell in the spreadsheet? Or prompt the user for values at runtime?

Further, I used to use a tool when I worked with DB2 that would take a list of values in a column of the spreadsheet and pass those to the query as part of the criteria. Is there a way to do this with PQ? Basically take a list of values in a worksheet and use them as the argument of an IN() statement to be sent to SQL server?

6 REPLIES 6
AntrikshSharma
Super User
Super User

@domtrump You can convert that list of values from  excel sheet into a List and then by using Table.SelectRows &  List.Contains you can filter the rows which database will treat as IN.

 

AntrikshSharma_0-1728125359939.png

 

Native Query:

AntrikshSharma_1-1728125400077.png

 

PwerQueryKees
Super User
Super User

Exact solution depends on the data type of your list and what syntax your need.

BUT, 

Lets say you have a table called Parameters and the column with the parameter values is called Values 

The expression Text.Combine(Parameters[Values],”, ")

Will give you a text string of all you parameter values separated by commas.

This works for number values. If you need quotes, you probably need to add a custom column in your Parameters table to include the quotes first.

Hmmm. Not totally sure I follow. Let's say my source table looks like this:

domtrump_0-1728078310914.png

My query to selct a subset of CustomerIDs would look like this (source is a query loading data from SQL Server)

domtrump_1-1728078360777.png

Now I create a new table in Excel called ParmTable. The user pastes the desired list of CustomerIDs into this table.

domtrump_2-1728078436643.png

This table has been loaded to PQ and then I right clicked it and hit Drill Down

domtrump_3-1728078495331.png 

domtrump_4-1728078523332.pngdomtrump_5-1728078544069.png

So now how would I modify my query to use the list of parameters from ParmTable instead of a hardcoded list?

 

domtrump_6-1728078887820.png

 

 

 

 

SqlQuery = "SELECT * FROM Sales where CustomerId in (" & Text.Combine(ParmTable, ",") & ")"

domtrump
Helper II
Helper II

Seems like this would work as a way to pass a single value (from a single cell) to a query. What if I needed to pass many values - a list of values - to the query? For example, If I have a list of 50 customer ID's and I paste them into a range of cells in the Excel workbook, I would want to pass these values to an "IN" statement in the WHERE clause of the query [WHERE CustomerID in (<list of values from range of cells>)] Is this possible? 

dufoq3
Super User
Super User

Hi @domtrump,

yes of course. You can import to power query all tables and named ranges. If you want to pass parameter from excel file to power query - just name ist i.e. myParameter

dufoq3_0-1706720148633.png

 

Then right clik on that cell --> Get Data from Table/Range

dufoq3_1-1706720183468.png

 

In Power Query right clik on value and Drill Down

dufoq3_2-1706720271137.png

 

Now you can use your parameter in SQL query but you need to add it like this (imaine dashes as your SQL code) - but maybe you have to use more quotes. Just try it but it works.

----------" & myParameter & "---------------------

 

 


Note: Check this link to learn how to use my query.
Check this link if you don't know how to provide sample data.

Helpful resources

Announcements
July 2025 community update carousel

Fabric Community Update - July 2025

Find out what's new and trending in the Fabric community.

July PBI25 Carousel

Power BI Monthly Update - July 2025

Check out the July 2025 Power BI update to learn about new features.

Join our Fabric User Panel

Join our Fabric User Panel

This is your chance to engage directly with the engineering team behind Fabric and Power BI. Share your experiences and shape the future.