web
You’re offline. This is a read only version of the page.
close
Skip to main content

Announcements

News and Announcements icon
Community site session details

Community site session details

Session Id :
Power Platform Community / Forums / Power Apps / Issue passing variable...
Power Apps
Answered

Issue passing variable to SQL Query

(0) ShareShare
ReportReport
Posted on by 118

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

 

Categories:
I have the same question (0)
  • Stuart74 Profile Picture
    118 on at

    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

  • Stuart74 Profile Picture
    118 on at

    Hello

     

    Thank you for your suggestions.

     

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

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

Introducing the 2026 Season 1 community Super Users

Congratulations to our 2026 Super Users!

Kudos to our 2025 Community Spotlight Honorees

Congratulations to our 2025 community superstars!

Congratulations to the April Top 10 Community Leaders!

These are the community rock stars!

Leaderboard > Power Apps

#1
Vish WR Profile Picture

Vish WR 742

#2
Valantis Profile Picture

Valantis 474

#3
Haque Profile Picture

Haque 358

Last 30 days Overall leaderboard