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
svishwanathan
Helper III
Helper III

Days between dates column not correctly computing

Hello


I am running two columns which cacluate days between dates and both are throwing incorrect results

 

Time to Close RFIs = IF(ISBLANK(RFIs[ANSWERED_DATE]),BLANK(),(RFIs[ANSWERED_DATE]-RFIs[SUBMITTED_DATE])*1.)

 

Lapse Days=Time to Close RFIs = IF([ANSWERED_DATE]> [Required Date],[ANSWERED_DATE]-[Required_DATE])*1.0,Blank())

1 ACCEPTED SOLUTION

Recreated your table and created two different calculated columns with the same results

 

datediff =
IF (
    DATEDIFF ( 'Table2'[RequiredDate], Table2[AnswerDate], DAY ) > 0,
    -1 * ( DATEDIFF ( 'Table2'[RequiredDate], Table2[AnswerDate], DAY ) ),
    DATEDIFF ( 'Table2'[RequiredDate], Table2[AnswerDate], DAY )
)

where

  • 'Table2' should be replaced with your table and
  • RequiredDate is PMSCRFI_ANSWERED_DATE and
  • AnswerDate is PMSCRFI_REQUIRED_DATE

Another Calculated column

datediff 2 =
IF (
    Table2[RequiredDate] < Table2[AnswerDate],
    -1 * DATEDIFF ( 'Table2'[RequiredDate], Table2[AnswerDate], DAY ),
    DATEDIFF ( 'Table2'[RequiredDate], Table2[AnswerDate], DAY )
)

These give the same result

 

datediff.PNG

View solution in original post

7 REPLIES 7
Anonymous
Not applicable

Have you tried using the DATEDIFF function instead?

 

https://msdn.microsoft.com/en-us/library/dn802538.aspx

I tried but doesnt help

 

Time to Resolve = SWITCH(TRUE(),RFIs[PMSCRFI_REQUIRED_DATE]<RFIs[PMSCRFI_ANSWERED_DATE],-1*DATEDIFF(RFIs[PMSCRFI_REQUIRED_DATE],RFIs[PMSCRFI_ANSWERED_DATE],DAY),RFIs[PMSCRFI_REQUIRED_DATE]>RFIs[PMSCRFI_ANSWERED_DATE],DATEDIFF(RFIs[PMSCRFI_ANSWERED_DATE],RFIs[PMSCRFI_REQUIRED_DATE],DAY),0)

 

 

2018-03-06_15-59-19.png

 

 

Recreated your table and created two different calculated columns with the same results

 

datediff =
IF (
    DATEDIFF ( 'Table2'[RequiredDate], Table2[AnswerDate], DAY ) > 0,
    -1 * ( DATEDIFF ( 'Table2'[RequiredDate], Table2[AnswerDate], DAY ) ),
    DATEDIFF ( 'Table2'[RequiredDate], Table2[AnswerDate], DAY )
)

where

  • 'Table2' should be replaced with your table and
  • RequiredDate is PMSCRFI_ANSWERED_DATE and
  • AnswerDate is PMSCRFI_REQUIRED_DATE

Another Calculated column

datediff 2 =
IF (
    Table2[RequiredDate] < Table2[AnswerDate],
    -1 * DATEDIFF ( 'Table2'[RequiredDate], Table2[AnswerDate], DAY ),
    DATEDIFF ( 'Table2'[RequiredDate], Table2[AnswerDate], DAY )
)

These give the same result

 

datediff.PNG

Thanks everyone for stepping in

 

Both your answers were correct

 

Yes my filter context in the table was incorrect which was giving inconsistent results

 

The forumlas provided below work great too

Anonymous
Not applicable

The formula does look like it produces the correct answer sometimes, but not all the time.

 

In your table, are you summarizing your Date fields in any way?  For example are you showing "First" or "Last" date for any reason?  I'm wondering if your data is in such a way that your formula is calculating using a different context to how your matrix is displaying the rows.

Anonymous
Not applicable

Can you share some sample data, what result you are getting and what result you are expecting?

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.