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

Register now to learn Fabric in free live sessions led by the best Microsoft experts. From Apr 16 to May 9, in English and Spanish.

Reply
fairy
New Member

which operator to use to compare date column with a date value?

Hi

I an trying to do the following while Adding a custom column. col1 and col2 are of date type

 

if [col1] < #date(2016,7,6) then "Grey"

else if ([col2] > #date(2016,7,6) and [col3] = "Yellow") then "Grey"

else [col3]

 

I get error saying cannot apply operator < to type Date. How do I compare dates in here?

 

 

 

1 ACCEPTED SOLUTION

You can change

#date(2016,7,6) 

to

#datetime(2016,7,6,0,0,0) 

and it should work 🙂

 

 

View solution in original post

3 REPLIES 3
arify
Employee
Employee

When I run "#date(2011,1,1) < #date(2015,1,1)" I get true, so that's not the issue.

 

What's the exact error message? Are you sure all of the column values are dates?

 

Are you getting something like this? We cannot apply operator < to types Date and DateTime.

 

Thanks

Yes that right. thats exactly the error message I get. how do I resolve this?

 

The workaround I did was use DAX in power BI desktop instead of M in Edit query. However, I still want the M to work

 

 

 

You can change

#date(2016,7,6) 

to

#datetime(2016,7,6,0,0,0) 

and it should work 🙂

 

 

Helpful resources

Announcements
Microsoft Fabric Learn Together

Microsoft Fabric Learn Together

Covering the world! 9:00-10:30 AM Sydney, 4:00-5:30 PM CET (Paris/Berlin), 7:00-8:30 PM Mexico City

PBI_APRIL_CAROUSEL1

Power BI Monthly Update - April 2024

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

April Fabric Community Update

Fabric Community Update - April 2024

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