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

Be one of the first to start using Fabric Databases. View on-demand sessions with database experts and the Microsoft product team to learn just how easy it is to get started. Watch now

Reply
ArjanVos
New Member

Pass a parameter from an Excel cell into a native SQL Query

Hi all,

 

I'm trying to pass an Excel cell value as a parameter to a native query (on a Progress database in Power Query in Excel).

I know how to pass an Excel cell value as a parameter to filter a table within Power Query. But we are working with big datasets, so I would like to apply the filter before the data is loaded. In this simple example I would like to replace ib240.cdstatus = ‘O’ by ib240.cdstatus = MyParameter.

 

 

 

let
    Source = Odbc.Query("dsn=Extended", "Select#(lf)    ib240.cdorder,#(lf)    ib240.cdstatus#(lf)From#(lf)    PUB.""ib-240"" ib240#(lf)Where#(lf)    ib240.cdstatus = 'O'")
in
    Source

 

 

 

I have tried using this example https://blog.crossjoin.co.uk/2016/12/11/passing-parameters-to-sql-queries-with-value-nativequery-in-...

 

My first step was to get this to work without using my parameter, like this:

 

 

 

let
    Source = Odbc.Query("dsn=Extended", "data"),
    Test = Value.NativeQuery(
        Source,
        "Select
            ib240.cdorder,
            ib240.cdstatus
        From
            PUB."ib-240" ib240
            Where
            ib240.cdstatus = 'O'
        ")
in
    Test

 

 

 

But then I'm getting an error:

 

pbi error.png

 

Can someone help me out here?

3 REPLIES 3
Jimmy801
Community Champion
Community Champion

Hello @ArjanVos 

 

You can add your parameter like this

let
    Source = Odbc.Query("dsn=Extended", "Select#(lf)    ib240.cdorder,#(lf)    ib240.cdstatus#(lf)From#(lf)    PUB.""ib-240"" ib240#(lf)Where#(lf)    ib240.cdstatus = '" & MyParameter & "'")
in
    Source


If this post helps or solves your problem, please mark it as solution (to help other users find useful content and to acknowledge the work of users that helped you)
Kudoes are nice too

Have fun

Jimmy

Hi Jimmy, almost a yea further now... Your solution seems to work only for parameters that I have defined within Power Quer but not for parameters that come from a cell value like in this link: https://exceleratorbi.com.au/pass-excel-parameter-power-query/

 

It then says this (in Dutch):

error pq.png

Freely translated: Query <Name> (step Source) refers to other queries or steps and therefore possibly doesn't have access to a data source. Make this data combination again.

 

Can we get this to work, so that we can make it as easy as possible for the end user to enter the parameters?

V-lianl-msft
Community Support
Community Support

Hi @ArjanVos ,

 

Try checking the symbol in the table name on line 9 according to the error message.

PUB.""ib-240"" ib240

 

Best Regards,
Liang
If this post helps, then please consider Accept it as the solution to help the other members find it more quickly.

Helpful resources

Announcements
Las Vegas 2025

Join us at the Microsoft Fabric Community Conference

March 31 - April 2, 2025, in Las Vegas, Nevada. Use code MSCUST for a $150 discount!

Dec Fabric Community Survey

We want your feedback!

Your insights matter. That’s why we created a quick survey to learn about your experience finding answers to technical questions.

ArunFabCon

Microsoft Fabric Community Conference 2025

Arun Ulag shares exciting details about the Microsoft Fabric Conference 2025, which will be held in Las Vegas, NV.

December 2024

A Year in Review - December 2024

Find out what content was popular in the Fabric community during 2024.