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

Grow your Fabric skills and prepare for the DP-600 certification exam by completing the latest Microsoft Fabric challenge.

Reply
hume
Regular Visitor

Operator < can not be applied to Date & DateTime

Hi,

 

I get an error message when trying to use the Table.SelectRows function to get data for the last 365 days only. I have tried it in PowerQuery Excel first and it works fine. In PowerBi Desktop however I get an error message saying the operator < can not be applied to types Date and DateTime. My [Date1] column is DateTime. I use the DateTime.LocalNow function to get the current date. To get the current date - 365 days, I use the Date.AddYear function. I am afraid that this function converts DateTime to Date and thus causing the error. Is this correct ? And if so, how can I solve this? There don't seem to be DateTime functions to calculate dates. Thanks in advance.

 

OperatorError.JPG

 

 

1 REPLY 1
MarcelBeug
Community Champion
Community Champion

Your Date1 column is of type datetime, which is the default for Excel date fields that are imported in Power Query.

The solution is to adjust your #"ChangedType" code and make sure Date1 is changed to date instead of datetime.

 

Date.AddYears doesn't convert datetime to date, but year a feeding Date.AddYears with a date from one of the DateTime functions that return dates: DateTime.Date.

 

You can use Date.AddYears for dates, datetimes and datetimezones; it will return the same data type as the data type of the input.

Specializing in Power Query Formula Language (M)

Helpful resources

Announcements
Europe Fabric Conference

Europe’s largest Microsoft Fabric Community Conference

Join the community in Stockholm for expert Microsoft Fabric learning including a very exciting keynote from Arun Ulag, Corporate Vice President, Azure Data.

RTI Forums Carousel3

New forum boards available in Real-Time Intelligence.

Ask questions in Eventhouse and KQL, Eventstream, and Reflex.

MayPowerBICarousel1

Power BI Monthly Update - May 2024

Check out the May 2024 Power BI update to learn about new features.