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
Anonymous
Not applicable

DAX DATEDIFF not working in some rows?

Hi,

 

I am trying to do a simple DATEDIFF between 2 date/time columns, but to my surprise it does work for the majority of the rows but not in all of them:

Imagen 2.png
 
 
How is it possible that it is giving the right value sometimes and a wrong value in other rows? it is just a simple DATEDIFF calculated column
 
Thanks!
5 REPLIES 5
az38
Community Champion
Community Champion

Hi @Anonymous 

Are you sure you have no duplicate rows? it looks like TimeToCreate has an aggregation in visual Values properties. Try to set Don't summarize

do not hesitate to kudo useful posts and mark solutions as solution
Linkedin


do not hesitate to give a kudo to useful posts and mark solutions as solution
LinkedIn
Anonymous
Not applicable

Yeah, I am sure, the Issue column is unique. Here you can see one of the wrong values in the data view:

Imagen 3.png

 

Thanks

az38
Community Champion
Community Champion

@Anonymous 

try to debug - create columns

=DAY(CreateDate)

=DAY(OccuredDate)

=YEAR(CreateDate)

=YEAR(OccuredDate)

=MONTH(CreateDate)

=MONTH(OccuredDate)

=HOUR(CreateDate)

=HOUR(OccuredDate)

 

and so on, then check if data in those fiels is correct 

 


do not hesitate to give a kudo to useful posts and mark solutions as solution
LinkedIn
Anonymous
Not applicable

wow,

 

It seems that in the createdate column the month is the day and the day is the month, like if it was reading the date in US format. It's really strange because in the query editor I have both columns with date/time format. What can I do to solve this?

 

Thanks

az38
Community Champion
Community Champion

@Anonymous 

it explains why your calculate works good within one day, but doesnt work with midnight inside the period

so, try to mix up the things

 

=DATEDIFF(
datevalue(concatenate(concatenate(day([Occured_Date]);"/");concatenate(MONTH([Occured_Date]);format([Occured_Date];"/YYYY HH:mm:ss"))));
datevalue(concatenate(concatenate(day([Create_Date]);"/");concatenate(MONTH([Create_Date]);format([Create_Date];"/YYYY HH:mm:ss"))));
SECONDS
)
/360

or replace DAY and MONTH functions

but the best way is to change format in the data source

 

do not hesitate to kudo useful posts and mark solutions as solution
Linkedin


do not hesitate to give a kudo to useful posts and mark solutions as solution
LinkedIn

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.