cancel
Showing results for 
Search instead for 
Did you mean: 

Fabric is Generally Available. Browse Fabric Presentations. Work towards your Fabric certification with the Cloud Skills Challenge.

Reply
CA
Frequent Visitor

Inconsistency with DateTime and accepted Operators?

I'm new to PowerBI and PowerQuery so this problem I've run into is really confusing me. What I'm trying to do is get a count of tickets created within the last 14 days and eventually plot the amount of issues per day against a chart. The second formula, a natural progression from my first formula, produces an error message that would make me think the first formula can't be valid, hence the confusion. That said...

 

Why does the valid formula below accept operators >, <, and =...

 

 

= if [CreatedDate] > DateTime.Date(DateTime.LocalNow()) then "1" else "0"

 

 

...But the next formula will spit an error if I use greater/less than operators:

 

if [CreatedDate] > Date.AddDays(DateTime.LocalNow(), -14) then "1" else "0"

 

 

The error I get is

"Expression.Error: We cannot apply operator < to types DateTime and Date.
Details:
    Operator=<
    Left=5/11/2017 5:19:17 PM
    Right=10/11/2014"

 

The error message can't be true since the first formula was accepted and produce the expected results. Any thoughts?

1 ACCEPTED SOLUTION
MarcelBeug
Community Champion
Community Champion

With the second formula, you omitted DateTime.Date. It should be:

 

if [CreatedDate] > Date.AddDays(DateTime.Date(DateTime.LocalNow()), -14) then "1" else "0"
Specializing in Power Query Formula Language (M)

View solution in original post

2 REPLIES 2
MarcelBeug
Community Champion
Community Champion

With the second formula, you omitted DateTime.Date. It should be:

 

if [CreatedDate] > Date.AddDays(DateTime.Date(DateTime.LocalNow()), -14) then "1" else "0"
Specializing in Power Query Formula Language (M)
CA
Frequent Visitor

Thank you SO much, this was killing me! I mulled over and over the syntax for an embarrassingly long time...

 

Thanks again!

Helpful resources

Announcements
PBI November 2023 Update Carousel

Power BI Monthly Update - November 2023

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

Community News

Fabric Community News unified experience

Read the latest Fabric Community announcements, including updates on Power BI, Synapse, Data Factory and Data Activator.

Dashboard in a day with date

Exclusive opportunity for Women!

Join us for a free, hands-on Microsoft workshop led by women trainers for women where you will learn how to build a Dashboard in a Day!

Power BI Fabric Summit Carousel

The largest Power BI and Fabric virtual conference

130+ sessions, 130+ speakers, Product managers, MVPs, and experts. All about Power BI and Fabric. Attend online or watch the recordings.

Top Solution Authors
Top Kudoed Authors