cancel
Showing results for 
Search instead for 
Did you mean: 
Reply
Highlighted
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

Accepted Solutions
Highlighted
Microsoft
Microsoft

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

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
Highlighted
Microsoft
Microsoft

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

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

Highlighted
New Member

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

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

 

 

 

Highlighted
Microsoft
Microsoft

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

You can change

#date(2016,7,6) 

to

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

and it should work 🙂

 

 

View solution in original post

Helpful resources

Announcements

August Community Highlights

Check out a full recap of the month!

Experience what’s next for Power BI

Join us for an in-depth look at the new Power BI features and capabilities at the free Microsoft Business Applications Launch Event.

Top Solution Authors