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
Milozebre
Helper V
Helper V

Condition with Datediff

 

Hello,
I have a problem with datediff.
I have 2 columns with dates (date 1 and date 2) in the format dd / mm / yyyy HH: MM.
theoretically date 2 is always larger than date 1. But I have exceptions.
Datediff (Date 1, Date2, Hour) does not work because I have the case.
I would like to make a condition: if date1> date 2 then we will have the resutat "null" otherwise datediff (date1, date2, hour)

thx

1 ACCEPTED SOLUTION
Milozebre
Helper V
Helper V

Hi Communauty, 

 

Thank you for your help. I tried for several days, different formulas but always the same results.

Queries in SQL were working. So I left 1-2 days to think. And when I got back to this problem, I found that I put the formule in a calculated column.

By doing a measure with a formula, it works.

 

I'm sorry about the hassle 🙂

 

Thanks again for the help.

View solution in original post

11 REPLIES 11
Milozebre
Helper V
Helper V

Hi Communauty, 

 

Thank you for your help. I tried for several days, different formulas but always the same results.

Queries in SQL were working. So I left 1-2 days to think. And when I got back to this problem, I found that I put the formule in a calculated column.

By doing a measure with a formula, it works.

 

I'm sorry about the hassle 🙂

 

Thanks again for the help.

Milozebre
Helper V
Helper V

good morning Phil, 

 

First thank you for your reply.

I'm sorry but it doesnt work. 

the result is null 

 

 

 

Hi,

 

If Phil's suggested formula does not work, then it means that entries in column 1 and 2 are text entries.  Convert them to actual dates and then the formula should work.


Regards,
Ashish Mathur
http://www.ashishmathur.com
https://www.linkedin.com/in/excelenthusiasts/

Hi Ashish_Mathur, 

 

I looked where the dates came from. I will be more specific. The two dates I am talking about are measures.
These are dates I take and I added a filter:

 

DatePriseEnCharge = CALCULATE(Min('Dossiers Traités/Actions'[DATE_ACTION]);'Dossiers Traités/Actions'[LibelleAction] = "Prise en compte par l'intervenant")

 

DatePriseEnCharge = CALCULATE(Min('Dossiers Traités/Actions'[DATE_ACTION]);'Dossiers Traités/Actions'[LibelleAction] = "Prise en compte par l'intervenant")

 

DelaiPriseencharge = DATEDIFF([DateActionMinAffectation];[DatePriseEnCharge];HOUR)

 

 

I hope this will help 🙂

 

Sorry if I misled you

 

 

Hi,

 

I do not see a mistake in any of those formulas.  I will need to see the file.


Regards,
Ashish Mathur
http://www.ashishmathur.com
https://www.linkedin.com/in/excelenthusiasts/

Hi, 

 

The queries work but when I do a simple datediff, I have a message that tells me I have a circular data error.
I would like to find the time difference between the 2 measures  "date affectation"  and the "date de prise en charge" by adding a condition.
If the "date de prise en charge" is smaller than the "date affection" then I want to see "error" otherwise make DATEDIFFF (dateaffectation; dateprisencharge; hour)
And for the file, it is so huge and in figure so-called private data...

 

Hi @Milozebre,

Please try to use the following formula and check if it works fine.

result=IF([date de prise en charge]<[date de prise en charge],blank(),DATEDIFFF([dateaffectation],[dateprisencharge],hour))


In your post above, the two formulas for creating measure for date are same?

Best Regards,
Angelia

Hi Angélia, 

 

Yes, i have make a mistake with the measures : 

 

DateActionMinAffectation = CALCULATE(Min('Dossiers Traités/Actions'[DATE_ACTION]);'Dossiers Traités/Actions'[LibelleAction] = "Affectation à l'équipe")

DatePriseEnCharge = CALCULATE(Min('Dossiers Traités/Actions'[DATE_ACTION]);'Dossiers Traités/Actions'[LibelleAction] = "Prise en compte par l'intervenant")

 

You can find in attachment the result... all rows are blank 

result.png

 

 

 

 

 

 

 

 

 

 

 

Hi @Milozebre,

The difference between the dates are tiny based on your screenshot. Please change the HOUR to SECOND in the measure. And check the results.

Best Regards,
Angelia

Hi communauty, 

 

i try several option woth if and iferror mais i have always same result.

 

i need your help 🙂

 

Thnak you in advance

Phil_Seamark
Employee
Employee

Hi @Milozebre

 

Its a bit ugly but you could try

 

Column = IFERROR(DATEDIFF('Table2'[Column1],'Table2'[Column2],HOUR),BLANK())

To learn more about DAX visit : aka.ms/practicalDAX

Proud to be a Datanaut!

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.