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

The Power BI Data Visualization World Championships is back! Get ahead of the game and start preparing now! Learn more

Reply
andyor
Resolver I
Resolver I

Importing Stored Procedure + Dynamic Date Parameter

I'm new to to Power BI and I've been researching how to import Stored Procedure's from Get Data query in PBI and someone said that the easiest way is to Execute in SQL Server, then copy in the execution code, as below.

 

 

 

DECLARE	@return_value int

EXEC	@return_value = [Reporting].[WallerNumbers]
		@TimeZoneID = 1,
		@TZStartDate = @start,
		@TZEndDate = @end,
		@DateType = 3

SELECT	'Return Value' = @return_value

EXEC	@return_value = [Reporting].[XXXXX]
		@TimeZoneID = 1,
		@TZStartDate = N'2022-09-01',
		@TZEndDate = N'2022-09-12',
		@DateType = 3

SELECT	'Return Value' = @return_value

 

 

 

This works fine but I have 2 questions from here:

 

1) Is this the best way to import into Power BI from a Stored Procedure?

2) How can I manipulate this to have the TZEndDate paramater be dynamic i.e.., getdate()? If I was using SSRS I would hard code this in the report parameters

1 ACCEPTED SOLUTION
andyor
Resolver I
Resolver I

The solution is to declare and set these in the import statement E.g., 

 

 

DECLARE	@return_value int
DECLARE @start datetime
DECLARE @end datetime

SET @start = DATEADD(Day, 0, DATEDIFF(Day, 0, GetDate()))
SET @end = getdate()

EXEC	@return_value = [Reporting].[XXXXX]
		@TimeZoneID = 1,
		@TZStartDate = @start,
		@TZEndDate = @end,
		@DateType = 3

SELECT	'Return Value' = @return_value

 

View solution in original post

1 REPLY 1
andyor
Resolver I
Resolver I

The solution is to declare and set these in the import statement E.g., 

 

 

DECLARE	@return_value int
DECLARE @start datetime
DECLARE @end datetime

SET @start = DATEADD(Day, 0, DATEDIFF(Day, 0, GetDate()))
SET @end = getdate()

EXEC	@return_value = [Reporting].[XXXXX]
		@TimeZoneID = 1,
		@TZStartDate = @start,
		@TZEndDate = @end,
		@DateType = 3

SELECT	'Return Value' = @return_value

 

Helpful resources

Announcements
Power BI DataViz World Championships

Power BI Dataviz World Championships

The Power BI Data Visualization World Championships is back! Get ahead of the game and start preparing now!

November Power BI Update Carousel

Power BI Monthly Update - November 2025

Check out the November 2025 Power BI update to learn about new features.

FabCon Atlanta 2026 carousel

FabCon Atlanta 2026

Join us at FabCon Atlanta, March 16-20, for the ultimate Fabric, Power BI, AI and SQL community-led event. Save $200 with code FABCOMM.