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

A new Data Days event is coming soon! This time we’re going bigger than ever. Fabric, Power BI, SQL, AI and more. Don't miss out.

Reply
cheid_4838
Helper IV
Helper IV

SQLDeclare Value in Power BI

I have a large query in SSRS that I would like to convert to power bi. I would like to import the query, but keep getting a "Must declare the scalar variable "@BillTo" and "@StartDate", "@EndDate", and "@StdRate".  How do I go about importing the query into power bi so that I can setup paramaters for these values?  Thanks.

 

 

 

--DECLARE @StartDate AS DATETIME DECLARE @EndDate AS DATETIME SET @StartDate = '10/29/2023' SET @EndDate = '11/3/2023' DECLARE @BillTo as varchar(max) SET @BillTo = 'CATGRI'
--DECLARE @StdRate as money SET @StdRate = 42.00 DECLARE @OTRate as money SET @OTRate = 42.00

 

 

, isnull((select top 1 ivd_rate from invoicedetail id (nolock) inner join invoiceheader ih (nolock) on ih.ivh_hdrnumber = id.ivh_hdrnumber where ih.ivh_billto = @BillTo and ih.ivh_deliverydate >= @StartDate and ih.ivh_deliverydate < @EndDate+1 and id.cht_itemcode = 'FSCMI' and ivd_rate <> 0),0) as FSCRate

 

WHERE ord_billto = @BillTo
AND o.ord_status = 'CMP'
AND o.ord_startdate >= @StartDate and o.ord_startdate < @EndDate+1

1 ACCEPTED SOLUTION

@cheid_4838 

yeah sorry,

declare your variables as parameters in Power Query and then replace any mentioning of that variable.

your @BillTo would become bill_to (variable) for example.






Any kudos or recognition appreciated. To learn more on the topic, check out my blog and follow me on LinkedIn.

View solution in original post

3 REPLIES 3
vojtechsima
Super User
Super User

Hello, @cheid_4838 ,

I would create Parameters in Power Query that you then reference in your query.

Since SQL query in PBI is just plain text, you can do it similry.

Example

"SELECT * FROM XX WHERE status = '"& text_parameter & "' "
Outcome
SELECT * FROM XX WHERE Status ='text'



vojtechsima_0-1730910814218.png

 






Any kudos or recognition appreciated. To learn more on the topic, check out my blog and follow me on LinkedIn.

Thanks for the recommendation.  I am not expert in SQL or power bi.  Would it be as simple as adding "& text_parameter &"" to replace  @BillTo or @startdate?

@cheid_4838 

yeah sorry,

declare your variables as parameters in Power Query and then replace any mentioning of that variable.

your @BillTo would become bill_to (variable) for example.






Any kudos or recognition appreciated. To learn more on the topic, check out my blog and follow me on LinkedIn.

Helpful resources

Announcements
May Power BI Update Carousel

Power BI Monthly Update - May 2026

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

Fabric SQL PBI Data Days

Data Days 2026 coming soon!

Sign up to receive a private message when registration opens and key events begin.

New to Fabric survey Carousel

New to Fabric Survey

If you have recently started exploring Fabric, we'd love to hear how it's going. Your feedback can help with product improvements.

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.