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

Next up in the FabCon + SQLCon recap series: The roadmap for Microsoft SQL and Maximizing Developer experiences in Fabric. All sessions are available on-demand after the live show. Register now

Reply
andyor
Resolver I
Resolver I

Direct Query with Date parameters

I am using DQ mode to query a basic table on TransactionDate. The issue is that the database times are UTC time, but the server is in local time. For this purpose, a function ufnToUTCTime() is called for all queries. 

 

If I envoke the function directly on the WHERE clause on TranscationDate, the query will take forever to run, as it's converting every single row toUTCTime. So in T-SQL I would DECLARE and SETthe @startdate and @enddate at the start and use these parameters in my where clause i.e., WHERE TransactionDate BETWEEN @startdate and @endate. 

 

When I try and declare and set in Direct Query mode, I get the following error 

 

andyor_0-1663994529078.png

 

How can I restucture my statement, such that it will be accepted for Direct Query mode? I have a temportary workaround in the meantime to use DATEADD(HOUR,-10) for the TransactionDate start and end dates. This will require me to change all queries back and forth to HOUR,-11 HOUR, -9 etc when daylight savings kicks in through the year

4 REPLIES 4
FarmerKenny
Helper II
Helper II

Can someone please solve this? I have the same issue. I want to keep the Date column that I am using as an expression in my Direct Query, AND also keep my parameter as a DATE data type, but Power BI is choking on that. It tries to evaluate it, but the query editor never finishes the query. 

amitchandak
Super User
Super User

@andyor , use m parameter and use them in the filter of query

https://learn.microsoft.com/en-us/power-bi/connect-data/desktop-dynamic-m-query-parameters

 

Try not to use declare.

 

Share with Power BI Enthusiasts: Full Power BI Video (20 Hours) YouTube
Microsoft Fabric Series 60+ Videos YouTube
Microsoft Fabric Hindi End to End YouTube

Thanks but don't think this will work as I need to use a database function ufnToUtcTime(), which converts the local time (server) to UTC time (database)

unless power BI has some inbuilt function that can do the same? (convert to UTC time)

Helpful resources

Announcements
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.

Join our Fabric User Panel

Join our Fabric User Panel

Share feedback directly with Fabric product managers, participate in targeted research studies and influence the Fabric roadmap.

March Power BI Update Carousel

Power BI Community Update - March 2026

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