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

Data Days is here! Join us now for 60+ days of learning, challenges, and connection. Learn more

Reply
HelloTheSun
Helper I
Helper I

NativeQuery with query parameter appear error when load to report

I create M-query code with "Value.NativeQuery" function which get input from query parameters.

after that I try to refresh in power query, there are not any error.

but when I load data to report then error is appear that must declare the variables?

My code

HelloTheSun_2-1697611734247.png


Error

HelloTheSun_4-1697611826085.png

 

please help me to solve this problem.

 

Thank.



4 REPLIES 4
Anonymous
Not applicable

Hi @HelloTheSun ,

Please try:

let
  //Connection
  Source = Sql.Database("10.16.89.71", "DWH"), 
  //Parameter
  _date_start = Date.ToText(
    #date(Date.Year(DateStart), Date.Month(DateStart), Date.Day(DateStart)), 
    "yyyy-MM-dd", 
    null
  ), 
  _date_end = Date.ToText(
    #date(Date.Year(DateEnd), Date.Month(DateEnd), Date.Day(DateEnd)), 
    "yyyy-MM-dd", 
    null
  ), 
  _pol_status = PolStat_Param, 
  //Native SQL
  _function = Value.NativeQuery(
    Source, 
    "SELECT * FROM [dbo].[Fn_TAProductionReport](@date_start,@date_end) 
        WHERE [PolicyStatus] = @pol_status", 
    [date_start = @_date_start, date_end = @_date_end, pol_status = @_pol_status], 
    [EnableFolding = true]
  ), 
  output = _function
in
  output

Best Regards,
Gao

Community Support Team

 

If there is any post helps, then please consider Accept it as the solution  to help the other members find it more quickly.
If I misunderstand your needs or you still have problems on it, please feel free to let us know. Thanks a lot!

How to get your questions answered quickly --  How to provide sample data in the Power BI Forum

Thank for reply

 

I try but it still the same error when load to report.

HelloTheSun_0-1697795501436.pngHelloTheSun_1-1697795542528.png

 

Anonymous
Not applicable

Hi @HelloTheSun ,

How about this:

let
  //Connection
  Source = Sql.Database("10.16.89.71", "DWH"), 
  //Parameter
  _date_start = Date.ToText(
    #date(Date.Year(DateStart), Date.Month(DateStart), Date.Day(DateStart)), 
    "yyyy-MM-dd", 
    null
  ), 
  _date_end = Date.ToText(
    #date(Date.Year(DateEnd), Date.Month(DateEnd), Date.Day(DateEnd)), 
    "yyyy-MM-dd", 
    null
  ), 
  _pol_status = PolStat_Param, 
  //Native SQL
  _function = Value.NativeQuery(
    Source, 
    "SELECT * FROM [dbo].[Fn_TAProductionReport](@_date_start,@_date_end) 
        WHERE [PolicyStatus] = @_pol_status", 
    [date_start = @_date_start, date_end = @_date_end, pol_status = @_pol_status], 
    [EnableFolding = true]
  ), 
  output = _function
in
  output

Best Regards,
Gao

Community Support Team

 

If there is any post helps, then please consider Accept it as the solution  to help the other members find it more quickly.
If I misunderstand your needs or you still have problems on it, please feel free to let us know. Thanks a lot!

How to get your questions answered quickly --  How to provide sample data in the Power BI Forum

Hi @Anonymous 
It doesn't work

HelloTheSun_0-1697797145356.pngHelloTheSun_1-1697797164578.png

 

Helpful resources

Announcements
Fabric Data Days is here Carousel

Fabric Data Days 2026

Don't miss out on Data Days, June 15 through August 7. Learn Fabric, Power BI, SQL, AI and more.

May Power BI Update Carousel

Power BI Monthly Update - May 2026

Check out the May 2026 Power BI update to learn about new features.

Power BI DataViz World Championships carousel

Power BI DataViz World Championships - June 2026

A new Power BI DataViz World Championship is coming this June! Don't miss out on submitting your entry.