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

Notifications

Announcements

Community site session details

Community site session details

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

Issue passing variable to SQL Query

(0) ShareShare
ReportReport
Posted on by 116

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
    116 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
    116 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

Forum hierarchy changes are complete!

In our never-ending quest to improve we are simplifying the forum hierarchy…

Ajay Kumar Gannamaneni – Community Spotlight

We are honored to recognize Ajay Kumar Gannamaneni as our Community Spotlight for December…

Leaderboard > Power Apps

#1
WarrenBelz Profile Picture

WarrenBelz 796 Most Valuable Professional

#2
Michael E. Gernaey Profile Picture

Michael E. Gernaey 327 Super User 2025 Season 2

#3
Power Platform 1919 Profile Picture

Power Platform 1919 268

Last 30 days Overall leaderboard