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

July 7 - July 17 | Round 2 of the Power BI Dataviz World Championships. Don't miss your chance! Learn more

Reply
AnupTandale
New Member

How to Filter Date/Time Columns in DirectQuery Mode Using M Query Parameters?


I am working with a table in DirectQuery mode in Power BI, and I need to filter a column of type `date/time` using slicers. Currently, the parameters `startDate` and `endDate` are of type `date` and bound to slicers. My M query for changing type of parameter and adding default time looks like this:

let
KustoParameterDeclareQuery = Text.Combine(
{
"declare query_parameters(",
"startTime:datetime = datetime(", Date.ToText(startDate, "yyyy-MM-dd") & " 00:00", "), ",
"endTime:datetime = datetime(", Date.ToText(endDate, "yyyy-MM-dd") & " 23:59", ")); "
}
),

Since `startDate` and `endDate` are of type `date`, I can't directly use them to filter columns of type `date/time`. When I attempt to change their type to `date/time` to match the column type, I get the following error:

"This type of transformation is not possible in DirectQuery mode."

Is there an alternative method to filter `date/time` columns using slicers, while staying within the limitations of DirectQuery mode? Iโ€™d like to avoid switching to Import mode or making significant changes to the existing setup.

Any suggestions or guidance would be greatly appreciated!

Thank you.

1 ACCEPTED SOLUTION
bhanu_gautam
Super User
Super User

@AnupTandale , Try using

 

let
startDateText = Date.ToText(startDate, "yyyy-MM-dd"),
endDateText = Date.ToText(endDate, "yyyy-MM-dd"),
KustoParameterDeclareQuery = Text.Combine(
{
"declare query_parameters(",
"startTime:datetime = datetime(", startDateText, " 00:00:00), ",
"endTime:datetime = datetime(", endDateText, " 23:59:59)); "
})
in
KustoParameterDeclareQuery

 

The startDate and endDate parameters are kept as date type, and the datetime values are constructed within the query using Date.ToText to format the dates and append the time portion.




Did I answer your question? Mark my post as a solution! And Kudos are appreciated

Proud to be a Super User!




LinkedIn






View solution in original post

2 REPLIES 2
Anonymous
Not applicable

Hi @AnupTandale ,

 

Thanks bhanu_gautam  for the quick reply and solution. I have some other ideas to add:
My test steps are as follows:

(1) You can change the parameter to be of type Date/Time. 

vtangjiemsft_0-1735889409994.png

vtangjiemsft_1-1735889453177.png

(2) Open the โ€œAdvancd Editorโ€ reference code:

 

let
    sqlQuery = "SELECT * FROM Calendar WHERE DateField >= '" & DateTime.ToText(StartTime, "yyyy-MM-dd hh:mm:ss") & "' AND DateField <= '" & DateTime.ToText(EndTime, "yyyy-MM-dd hh:mm:ss") & "';",
    Source = Sql.Database("vm0", "DateDatabase", [Query=sqlQuery])
in
    Source

 

(3) Create two slicer tables and then bind the parameters.

Start = CALENDAR(DATE(2024,1,1),DATE(2024,1,31))
End = CALENDAR(DATE(2024,1,1),DATE(2024,1,31))

vtangjiemsft_0-1735891871878.png

vtangjiemsft_1-1735891905898.png

(4) Result:

vtangjiemsft_2-1735892020853.png

Best Regards,

Neeko Tang

If this postโ€ฏ helps, then please considerโ€ฏAccept it as the solution โ€ฏto help the other members find it more quickly. 

bhanu_gautam
Super User
Super User

@AnupTandale , Try using

 

let
startDateText = Date.ToText(startDate, "yyyy-MM-dd"),
endDateText = Date.ToText(endDate, "yyyy-MM-dd"),
KustoParameterDeclareQuery = Text.Combine(
{
"declare query_parameters(",
"startTime:datetime = datetime(", startDateText, " 00:00:00), ",
"endTime:datetime = datetime(", endDateText, " 23:59:59)); "
})
in
KustoParameterDeclareQuery

 

The startDate and endDate parameters are kept as date type, and the datetime values are constructed within the query using Date.ToText to format the dates and append the time portion.




Did I answer your question? Mark my post as a solution! And Kudos are appreciated

Proud to be a Super User!




LinkedIn






Helpful resources

Announcements
FabCon and SQLCon Barcelona 2026

FabCon & SQLCon โ€“ Barcelona 2026

Join us in Barcelona for FabCon and SQLCon, the Fabric, Power BI, SQL, and AI community event. Save โ‚ฌ200 with code FABCMTY200.

60 days of Data Days Carousel

Data Days 2026

Join Fabric Data Days 2026: 60 days of free live/on-demand sessions, challenges, study groups, and certification opportunities.

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.