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
akhaliq7
Post Prodigy
Post Prodigy

Implementing SQL query parameters in Power BI/Power Query

Problem

I have been given a sql query which has two parameters called start_date and end_date, need to show the exact same data in power bi.

 

Current Methods to import data

I currently create a sql view and import it, don't have any experience using parameters.

 

Background

I am importing the previous 5 years of data using hardcoded values instead of parameters But as the query is really complicated as it is using unions, where in and where not in and the date filter is in multiple queries I know this method will not return the correct  number of rows.  Therefore my current method will not work instead need to use parameters.

 

With the limited information given even if someone can either guide me as to there process when dealing with parameters in sql and implementing the same in power query/power bi or even share a link etc. 

1 ACCEPTED SOLUTION
OwenAuger
Super User
Super User

Hi @akhaliq7 

One idea: Create a table-valued function, then query this function using the Power Query interface.

 

Here's a table-valued function I created to test:

CREATE OR ALTER FUNCTION DateTable (
	@StartDate DATE
	,@EndDate DATE
	)
RETURNS TABLE
AS
RETURN

SELECT [FullDateAlternateKey], [CalendarYear], [MonthNumberOfYear]
FROM [AdventureWorksDW].[dbo].[DimDate]
WHERE [FullDateAlternateKey] BETWEEN @StartDate AND @EndDate

 

Then in Power Query, you connect to this function, which is exposed as a Power Query function, and populate the parameters using whatever means you like:

OwenAuger_0-1697678756221.png

Would something like this work for you?

Regards


Owen Auger
Did I answer your question? Mark my post as a solution!
Blog
LinkedIn

View solution in original post

1 REPLY 1
OwenAuger
Super User
Super User

Hi @akhaliq7 

One idea: Create a table-valued function, then query this function using the Power Query interface.

 

Here's a table-valued function I created to test:

CREATE OR ALTER FUNCTION DateTable (
	@StartDate DATE
	,@EndDate DATE
	)
RETURNS TABLE
AS
RETURN

SELECT [FullDateAlternateKey], [CalendarYear], [MonthNumberOfYear]
FROM [AdventureWorksDW].[dbo].[DimDate]
WHERE [FullDateAlternateKey] BETWEEN @StartDate AND @EndDate

 

Then in Power Query, you connect to this function, which is exposed as a Power Query function, and populate the parameters using whatever means you like:

OwenAuger_0-1697678756221.png

Would something like this work for you?

Regards


Owen Auger
Did I answer your question? Mark my post as a solution!
Blog
LinkedIn

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.