Skip to main content

Notifications

Community site session details

Community site session details

Session Id :
Power Apps - Power Query
Answered

Issue passing variable to SQL Query

(0) ShareShare
ReportReport
Posted on by 112

Hello

 

I am writing a Power Query to extract data from a SQL Database.  I wish to filter the data extracted.

I have tried one step being the SQL query, and then the second step the filter, but that ends up with the Power Query loading all rows from the database before filtering, or thats what it looks like.

 

So I then tried referencing a variable/parameter in the SQL step.  This is the bit I need help with.

 

The variable is a value from the a sheet,

Stuart74_0-1689328755394.png

Stuart74_1-1689328767877.png

 

But then I get this when I try to use

Stuart74_2-1689328872304.png

 

 

Please does any one have any advice?

 

Thank you

 

Stuart

 

  • Stuart74 Profile Picture
    112 on at
    Re: Issue passing variable to SQL Query

    Hello

     

    Thank you for your suggestions.

     

    I did what you suggested and it worked.  Thank you.

  • Stuart74 Profile Picture
    112 on at
    Re: Issue passing variable to SQL Query

    Hello

     

    Thank you for your suggestions.

    I have made some changes and have shown below.  This runs, returns the right result, but I am unsure if it works correctly.

     

     

    Parameters (GetVar)

    Code;

     

    (ParameterName as text) =>
    let
    ParamSource = Excel.CurrentWorkbook(){[Name="Parameters"]}[Content],
    ParamRow = Table.SelectRows(ParamSource, each ([Parameter] = ParameterName)),
    Value=
    if Table.IsEmpty(ParamRow)=true
    then null
    else Record.Field(ParamRow{0},"Input")
    in
    Value

     

    Query with SQL

     

    Stuart74_0-1689352927829.png

     

    I let it run for 15 mins, it counted to 15million plus rows, then loaded 884k rows.  So the right result, BUT;

     

    Please can you advise is this is working correctly?  The query in SQL Mgmt Studio takes about 50 seconds with the same parameters.

     

    Thanks

     

    Stuart

Under review

Thank you for your reply! To ensure a great experience for everyone, your content is awaiting approval by our Community Managers. Please check back later.

Helpful resources

Quick Links

🌸 Community Spring Festival 2025 Challenge Winners! 🌸

Congratulations to all our community participants!

Warren Belz – Community Spotlight

We are honored to recognize Warren Belz as our May 2025 Community…

Congratulations to the April Top 10 Community Stars!

Thanks for all your good work in the Community!

Leaderboard > Power Apps - Power Query

#1
mmbr1606 Profile Picture

mmbr1606 9 Super User 2025 Season 1

#2
SD-13050734-0 Profile Picture

SD-13050734-0 6

#3
Jon Unzueta Profile Picture

Jon Unzueta 2

Overall leaderboard

Featured topics