- Subscribe to RSS Feed
- Mark Topic as New
- Mark Topic as Read
- Float this Topic for Current User
- Bookmark
- Subscribe
- Printer Friendly Page
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
Keep getting "Expression.Error: We cannot apply operator < to types Date and DateTime" - please help
I have the following M code in Query Editor from power BI:
let Source = Sql.Database("DB", "DB", [CommandTimeout=#duration(0, 1, 0, 0)]), dbo_Calls = Source{[Schema="dbo",Item="Calls"]}[Data], #"Changed Type" = Table.TransformColumnTypes(dbo_Calls,{{"Completion Date", type date}}), EndDate = Date.From(DateTime.FixedLocalNow()), StartDate = Date.AddDays(Date.AddMonths(EndDate,-6),1), #"Filtered Rows" = Table.SelectRows(dbo_Calls,each [Completion Date]>=StartDate and [Completion Date]<=EndDate) in #"Filtered Rows"
However this results in the below error:
Expression.Error: We cannot apply operator < to types Date and DateTime. Details: Operator=< Left=26/12/2018 Right=16/05/2017 00:00:00
Any ideas how I can get around this?
Many thanks for all help
Solved! Go to Solution.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
Hi,
You could either change the datetime column to date or the other way around.
Or you could try adding DateTime.From() to the date columns.
I don't know which one is the datetime columns so i added the function it to all of them.
#"Filtered Rows" = Table.SelectRows(dbo_ANSAPBICalls,each DateTime.From([Completion Date])>=DateTime.From(StartDate) and DateTime.From([Completion Date])<=DateTime.From(EndDate))
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
You are comparing Date format with Datetime format. Change the format from datetime to date on your start and enddate before the filterstatement and it should work fine!
/J
Connect on LinkedIn
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
Its fixed now. I changed all Date functions to DateTime. I also amended the Filtered Rows step so it was using SelectRows from #ChangedType step, not from the original data source:
let Source = Sql.Database("DB", "DB", [CommandTimeout=#duration(0, 1, 0, 0)]), dbo_Calls = Source{[Schema="dbo",Item="Calls"]}[Data], #"Changed Type" = Table.TransformColumnTypes(dbo_Calls,{{"Completion Date", type date}}), EndDate = Date.From(DateTime.FixedLocalNow()), StartDate = Date.AddDays(Date.AddMonths(EndDate,-6),1), #"Filtered Rows" = Table.SelectRows(#"Changed Type",each DateTime.From([Completion Date])>=DateTime.From(StartDate) and DateTime.From([Completion Date])<=DateTime.From(EndDate)) in #"Filtered Rows"
Thats done the trick, cheers for all the help!
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
I had the same problem, it was caused by a manually added stop-date (used by incremental refresh) with a non exsisting date: 31.06.2023 00:00:00
Because June only has 30 days, I changed it to 30.06.2023 00:00:00
It solved the problem.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
You are comparing Date format with Datetime format. Change the format from datetime to date on your start and enddate before the filterstatement and it should work fine!
/J
Connect on LinkedIn
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
Thank you both
I have amended my M code to below:
EndDate = Date.From(Date.FixedLocalNow()), StartDate = Date.AddDays(Date.AddMonths(EndDate,-6),1), #"Filtered Rows" = Table.SelectRows(dbo_Calls,each Date.From([Completion Date])>=Date.From(StartDate) and Date.From([Completion Date])<=Date.From(EndDate))
However I now get below error:
Expression.Error: The name 'Date.FixedLocalNow' wasn't recognized. Make sure it's spelled correctly.
Am I doing something daft here??
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
There is no function called Date.FixedLocalNow() which is why you get an error. DateTime.FixedLocalNow() is the name of that function.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
I cant really tell whats wrong, can you post the complete query code?
Connect on LinkedIn
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
Its fixed now. I changed all Date functions to DateTime. I also amended the Filtered Rows step so it was using SelectRows from #ChangedType step, not from the original data source:
let Source = Sql.Database("DB", "DB", [CommandTimeout=#duration(0, 1, 0, 0)]), dbo_Calls = Source{[Schema="dbo",Item="Calls"]}[Data], #"Changed Type" = Table.TransformColumnTypes(dbo_Calls,{{"Completion Date", type date}}), EndDate = Date.From(DateTime.FixedLocalNow()), StartDate = Date.AddDays(Date.AddMonths(EndDate,-6),1), #"Filtered Rows" = Table.SelectRows(#"Changed Type",each DateTime.From([Completion Date])>=DateTime.From(StartDate) and DateTime.From([Completion Date])<=DateTime.From(EndDate)) in #"Filtered Rows"
Thats done the trick, cheers for all the help!
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
Hi,
You could either change the datetime column to date or the other way around.
Or you could try adding DateTime.From() to the date columns.
I don't know which one is the datetime columns so i added the function it to all of them.
#"Filtered Rows" = Table.SelectRows(dbo_ANSAPBICalls,each DateTime.From([Completion Date])>=DateTime.From(StartDate) and DateTime.From([Completion Date])<=DateTime.From(EndDate))

Helpful resources
Join us at the Microsoft Fabric Community Conference
March 31 - April 2, 2025, in Las Vegas, Nevada. Use code MSCUST for a $150 discount!
Power BI Monthly Update - February 2025
Check out the February 2025 Power BI update to learn about new features.

Subject | Author | Posted | |
---|---|---|---|
03-02-2022 10:50 AM | |||
08-21-2024 06:40 AM | |||
07-24-2023 08:17 AM | |||
12-01-2023 01:49 AM | |||
09-10-2023 09:25 PM |
User | Count |
---|---|
87 | |
81 | |
53 | |
38 | |
35 |