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

Power BI is turning 10! Let’s celebrate together with dataviz contests, interactive sessions, and giveaways. Register now.

Reply
danyeungw
Helper II
Helper II

How to select a date as a parameter for a direct query?

Hello,

I need to create a dashboard to let the users select a Report Date, and pass the date to a direct query to SQL Server.

I am looking for how to create and select a date as a parameter for a direct query. Hope to get help here.

 

What I have done below may not be in correct direction. 

I created a "Report Date" query that contains last 90 days. I also created a ReportDateParameter that used the "Report Date" query.

I created a direct query "where ld.ReportDate = '", each Date.ToText([ReportDateParameter],"MM/dd/yyyy"), "'".  That has 

Expression.Error: We cannot convert a value of type Function to type Text.
Details:
Value=[Function]

 

Thanks.
Type=[Type]

 

 

2 REPLIES 2
JaromG
Frequent Visitor

It looks like you are trying to create a dashboard in Power BI that allows users to select a Report Date and pass that date as a parameter for a direct query to SQL Server. Based on the information you provided, it seems you are on the right track, but there might be a small issue in the way you are trying to pass the parameter. To create a parameter for a direct query in Power BI, you can follow these steps: Create a Parameter: Go to the Power Query Editor, click on "Home," and then select "Manage Parameters." Create a new parameter, let's call it "ReportDateParameter," and specify the data type as "Date/Time." Define a Date Range Query: Create a new query that generates the date range you want to use for the user selection. It seems you have already done this step by creating the "Report Date" query that contains the last 90 days. Set the Parameter Value: In the "Report Date" query, you can use the parameter you created ("ReportDateParameter") to allow the user to select a specific date. Instead of using each Date.ToText([ReportDateParameter],"MM/dd/yyyy"), you can simply reference the parameter like this: [ReportDateParameter]. Use the Parameter in the Direct Query: In your direct query, where you have "where ld.ReportDate = '", you can modify it to "where ld.ReportDate = '" & Text.From([ReportDateParameter], "MM/dd/yyyy") & "'". This will convert the date from the parameter to the appropriate text format for the SQL query. With these adjustments, your direct query should be able to use the selected date from the "ReportDateParameter" to filter data in SQL Server. If you encounter any issues after making these changes, please feel free to share the updated code or any error messages you receive, and I'll be glad to assist you further. Good luck with your Power BI dashboard!

Thanks JaromG,
I changed it to "where ld.ReportDate = '" & Text.From([ReportDateParameter],"MM/dd/yyyy") & "'".

Now I received another error 

Expression.Error: There is an unknown identifier. Did you use the [field] shorthand for a _[field] outside of an 'each' expression?

Helpful resources

Announcements
Join our Fabric User Panel

Join our Fabric User Panel

This is your chance to engage directly with the engineering team behind Fabric and Power BI. Share your experiences and shape the future.

June 2025 Power BI Update Carousel

Power BI Monthly Update - June 2025

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

June 2025 community update carousel

Fabric Community Update - June 2025

Find out what's new and trending in the Fabric community.