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
Vtomsons
Helper I
Helper I

Calculate time between two dates

Hi,

 

Trying to do a simple calculation of days between two dates but although their are no syntax errors in my custom column and error "Expression Error: The name "DATEDIFF" wasn't recognized. Make sure its spelled correctly" comes up. Here's my formula:

 

DATEDIFF(MIN( Calendar[Enrollment date.Current Registration Status Date] ), MAX( Calendar[Last Accessed]), DAY)

 

I joined two separate tables so that my dates are in the same Query but I don't think that's the issue. What am I doing wrong?

 

Thanks,

 

Val

2 ACCEPTED SOLUTIONS
Greg_Deckler
Super User
Super User

(MIN( Calendar[Enrollment date.Current Registration Status Date] ) - MAX( Calendar[Last Accessed]) * 1.


@ me in replies or I'll lose your thread!!!
Instead of a Kudo, please vote for this idea
Become an expert!: Enterprise DNA
External Tools: MSHGQM
YouTube Channel!: Microsoft Hates Greg
Latest book!:
The Definitive Guide to Power Query (M)

DAX is easy, CALCULATE makes DAX hard...

View solution in original post

v-kelly-msft
Community Support
Community Support

Hi @Vtomsons

 

If it needs to be done in power query,using below M code:

 

Custom = Duration.Days([Date2]-[Date])

 

And you will see:

Annotation 2020-04-21 133719.png

 

If it is done in report view,using below dax expression to create a measure:

 

Measure = DATEDIFF(SELECTEDVALUE('Table'[Date2]),SELECTEDVALUE('Table'[Date]),DAY)

 

And you will see:

Annotation 2020-04-21 134524.png

Or you can create a calculated column as below:

 

Column = DATEDIFF('Table'[Date],'Table'[Date2],DAY)

 

And you will see:

Annotation 2020-04-21 134721.png

 

Hope the above is what you need.

 

Best Regards,
Kelly
Did I answer your question? Mark my post as a solution!

 

View solution in original post

6 REPLIES 6
v-kelly-msft
Community Support
Community Support

Hi @Vtomsons

 

If it needs to be done in power query,using below M code:

 

Custom = Duration.Days([Date2]-[Date])

 

And you will see:

Annotation 2020-04-21 133719.png

 

If it is done in report view,using below dax expression to create a measure:

 

Measure = DATEDIFF(SELECTEDVALUE('Table'[Date2]),SELECTEDVALUE('Table'[Date]),DAY)

 

And you will see:

Annotation 2020-04-21 134524.png

Or you can create a calculated column as below:

 

Column = DATEDIFF('Table'[Date],'Table'[Date2],DAY)

 

And you will see:

Annotation 2020-04-21 134721.png

 

Hope the above is what you need.

 

Best Regards,
Kelly
Did I answer your question? Mark my post as a solution!

 

Thanks fellas for the insight. New to all this so it will get easier...I hope.

Greg_Deckler
Super User
Super User

(MIN( Calendar[Enrollment date.Current Registration Status Date] ) - MAX( Calendar[Last Accessed]) * 1.


@ me in replies or I'll lose your thread!!!
Instead of a Kudo, please vote for this idea
Become an expert!: Enterprise DNA
External Tools: MSHGQM
YouTube Channel!: Microsoft Hates Greg
Latest book!:
The Definitive Guide to Power Query (M)

DAX is easy, CALCULATE makes DAX hard...

Still getting the error"the name MIN wasn't recognized. Make sure its spelled correctly"

 

Do these two date columns need to be formatted some way? I have them in the date/time

And make sure that you are somewhere that you should be entering DAX code, and not in Query Editor.


@ me in replies or I'll lose your thread!!!
Instead of a Kudo, please vote for this idea
Become an expert!: Enterprise DNA
External Tools: MSHGQM
YouTube Channel!: Microsoft Hates Greg
Latest book!:
The Definitive Guide to Power Query (M)

DAX is easy, CALCULATE makes DAX hard...

Oh, dude,

Measure = (MIN( Calendar[Enrollment date.Current Registration Status Date] ) - MAX( Calendar[Last Accessed]) * 1.

@ me in replies or I'll lose your thread!!!
Instead of a Kudo, please vote for this idea
Become an expert!: Enterprise DNA
External Tools: MSHGQM
YouTube Channel!: Microsoft Hates Greg
Latest book!:
The Definitive Guide to Power Query (M)

DAX is easy, CALCULATE makes DAX hard...

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.