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

Get certified in Microsoft Fabric—for free! For a limited time, get a free DP-600 exam voucher to use by the end of 2024. Register now

Reply
Anonymous
Not applicable

We cannot apply operator - to types Function and Date

Hi all...

 

I am trying to find the difference, in days, from today's date and a Report date. If the difference is greater than or equal to 60 days, produce a 1, else a 0. I am receiving a "We cannot apply operator - to types Function and Date" error with the expression below. The data type for Report Date is date, and I'm thinking the error has something to do with trying to compare a date/time field with a date field.

each if Duration.Days(DateTime.LocalNow - [Report Date]) >= 60 then 1 else 0

 

Kudos to anyone who can assist here.

1 ACCEPTED SOLUTION
mahoneypat
Microsoft Employee
Microsoft Employee

Please try this instead

 

each if Duration.TotalDays(Date.From(DateTime.LocalNow()) - [Date]) <=60 then 1 else 0

 

Pat

 





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

To learn more about Power BI, follow me on Twitter or subscribe on YouTube.


@mahoneypa HoosierBI on YouTube


View solution in original post

2 REPLIES 2
mahoneypat
Microsoft Employee
Microsoft Employee

Please try this instead

 

each if Duration.TotalDays(Date.From(DateTime.LocalNow()) - [Date]) <=60 then 1 else 0

 

Pat

 





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

To learn more about Power BI, follow me on Twitter or subscribe on YouTube.


@mahoneypa HoosierBI on YouTube


Anonymous
Not applicable

Great. Thank you! Looks like that converts the DateTime format to date at which point it can be compared to my Report Date column.

Helpful resources

Announcements
November Carousel

Fabric Community Update - November 2024

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

Live Sessions with Fabric DB

Be one of the first to start using Fabric Databases

Starting December 3, join live sessions with database experts and the Fabric product team to learn just how easy it is to get started.

Las Vegas 2025

Join us at the Microsoft Fabric Community Conference

March 31 - April 2, 2025, in Las Vegas, Nevada. Use code MSCUST for a $150 discount! Early Bird pricing ends December 9th.

Nov PBI Update Carousel

Power BI Monthly Update - November 2024

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