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

Don't miss out! 2025 Microsoft Fabric Community Conference, March 31 - April 2, Las Vegas, Nevada. Use code MSCUST for a $150 discount. Prices go up February 11th. Register now.

Reply
DanJaz85
Frequent Visitor

Need help with this M query please

As per below screenshot, parameters were defined in the parameter section of Power BI.

 

DanJaz85_0-1725243440617.png

 

And I have below query to get the data from SQL database via the stored procedure. When refresh the query it doesn't load the data from SP query outpout, instead load entire tables, views and functions list from the database as the output.

 

can someone please help me to fix the below data source. I just want to execute below SP by passing the parameters dynamically and load into Power BI. thanks

 

let
Source = Sql.Database("MyServer", "My_DB", [Query="EXECUTE My_DB_SP "&Text.From(WhseFrom)&","&Text.From(WhseTo)&","&Text.From(FactoryFrom)&","&Text.From(FactoryTo)&","&Text.From(DateTo)&","&Text.From(DateOffestTo)&","&Text.From(DateFrom)&","&Text.From(DateOffsetFrom)])
in
Source

 

@Greg_Deckler @rajendraongole1 @lbendlin @SamWiseOwl @Ritaf1983 

3 REPLIES 3
lbendlin
Super User
Super User

You need to add the single quotes around your SP parameters.

Hi @lbendlin 

thanks for that.

 

I tried with single quotes too. but it didn't work either.

 

intead of SP, I'm trying to run the SQL query directly, but I still get below error on the parameters.

= Sql.Database("MyServer", "My_DB", [Query="SELECT
COUNT(distinct c.co_num) AS [Total Order Count],
CAST(SUM(it.uf_emdaSQMperUnit * co.qty_ordered)AS DECIMAL (18,2))AS M2,
CAST(SUM(it.uf_emdaKgMtr * uf_emdaLength * co.qty_ordered) AS DECIMAL (18,2)) AS [Weight]
FROM co_mst c WITH (NOLOCK)
JOIN coitem_mst co WITH (NOLOCK)
ON c.co_num = co.co_num
JOIN item_mst it WITH (NOLOCK)
ON co.item = it.item
WHERE
CAST(c.order_date AS DATE) = '"DateFrom"'
AND c.whse BETWEEN '"WhseFrom"' AND '"WhseTo"'
AND ISNULL(c.uf_emdaFactory,'') BETWEEN ISNULL('"FactoryFrom"','') AND ISNULL('"FactoryTo"','')
AND c.stat = 'O'
AND co.qty_ordered > 0"])

 

below is the error I get for above query

DanJaz85_0-1725406924928.png

when I add && on the parameters, it returns below error

DanJaz85_1-1725407042969.png

 

any help would be greatly appreciated

CAST(c.order_date AS DATE) = '" & DateFrom & "'

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!

Jan25PBI_Carousel

Power BI Monthly Update - January 2025

Check out the January 2025 Power BI update to learn about new features in Reporting, Modeling, and Data Connectivity.

December 2024

A Year in Review - December 2024

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

Top Kudoed Authors