Skip to main content
cancel
Showing results for 
Search instead for 
Did you mean: 

Earn a 50% discount on the DP-600 certification exam by completing the Fabric 30 Days to Learn It challenge.

Reply
Anonymous
Not applicable

calculated date difference from different months giving negative value

Trying to create a calculated column that takes the difference between 2 different dates.  However I'm running into an issue where the formula is not recognizing the values that are from 2 different months. 

 

For example:  Wed, June 20 (DoneDate) - Thur, July 12 (ToDoDate) will get me a negative value of -8 rather than giving me 22.

 

Here is the formula i'm using:

Time = IF(OR(ISBLANK('Table1'[DoneDate].[Day]), ISBLANK('Table1'[ToDoDate].[Day])), 0, DATEDIFF('Table1'[ToDoDate].[Day],'Table1'[DoneDate].[Day], DAY))

 

Calcuation will work just fine if the dates are in the same month.  

1 ACCEPTED SOLUTION
v-piga-msft
Resident Rockstar
Resident Rockstar

Hi @Anonymous,

 

It seems that you may modify your formula like below.

 

Time =
IF (
    OR (
        ISBLANK ( 'Table1'[DoneDate].[Day] ),
        ISBLANK ( 'Table1'[ToDoDate].[Day] )
    ),
    0,
    DATEDIFF ( 'Table1'[DoneDate], 'Table1'[ToDoDate], DAY )
)

By my test with Power BI Desktop Version: 2.61.5192.541 64-bit (August 2018), everyhing works as expected.

 

Dateiff.PNG

 

If you still need help, please share your sample data and your desired output.

 

Best  Regards,

Cherry

Community Support Team _ Cherry Gao
If this post helps, then please consider Accept it as the solution to help the other members find it more quickly.

View solution in original post

2 REPLIES 2
v-piga-msft
Resident Rockstar
Resident Rockstar

Hi @Anonymous,

 

It seems that you may modify your formula like below.

 

Time =
IF (
    OR (
        ISBLANK ( 'Table1'[DoneDate].[Day] ),
        ISBLANK ( 'Table1'[ToDoDate].[Day] )
    ),
    0,
    DATEDIFF ( 'Table1'[DoneDate], 'Table1'[ToDoDate], DAY )
)

By my test with Power BI Desktop Version: 2.61.5192.541 64-bit (August 2018), everyhing works as expected.

 

Dateiff.PNG

 

If you still need help, please share your sample data and your desired output.

 

Best  Regards,

Cherry

Community Support Team _ Cherry Gao
If this post helps, then please consider Accept it as the solution to help the other members find it more quickly.
Anonymous
Not applicable

Thank you! I didn't realize I was just looking at the [Day] value while doing my calculation.  Works great!

Helpful resources

Announcements
LearnSurvey

Fabric certifications survey

Certification feedback opportunity for the community.

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.