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

Get Fabric Certified for FREE during Fabric Data Days. Don't miss your chance! Request now

Reply
setis
Post Partisan
Post Partisan

DateDiff unexpected results

Dear all, 

 

I am calculating a new column with the difference in days of [Due Date] and  [Posting Date]. I am using a simple DATEDIFF function:

DatediffFunction.PNG

 

This is giving me bad results in some cases:

Dadediff Wrong.PNG

 

and good results in most of the table:

DatediffRight.PNG

 

This doesn't make any sense to me at all. Can anybody give me an idea of what could be wrong?

 

On a separate note, is it possible to show the DATEDIFF values on positive and negative values? If Posting Date is after the due date, I would like a positive value and not 0

 

Thanks in advance

1 ACCEPTED SOLUTION
v-yulgu-msft
Microsoft Employee
Microsoft Employee

Hi @setis,

 

 I tested with above DAX formula, it returns correct datediff results.

1.PNG

 

In your scenario, please check if the results are correct in Data view as shown in above screenshot. If you have several duplicate rows, when you add fields into table visual, [Diff PostingDate & DueDate] might be aggregated which returns larger values.

 


On a separate note, is it possible to show the DATEDIFF values on positive and negative values? If Posting Date is after the due date, I would like a positive value and not 0

 


You can use a IF condition in such a scenario. Similar to:

 

Diff PostingDate & DueDate =
VAR datediffval =
    DATEDIFF (
        'Sample Table'[Due Date].[Date],
        'Sample Table'[Posting Date].[Date],
        DAY
    )
RETURN
    IF (
        'Sample Table'[Posting Date].[Date] > 'Sample Table'[Due Date].[Date],
        ABS ( datediffval ),
        datediffval
    )
 
 
Best regards,
Yuliana Gu
Community Support Team _ Yuliana Gu
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

3 REPLIES 3
v-yulgu-msft
Microsoft Employee
Microsoft Employee

Hi @setis,

 

 I tested with above DAX formula, it returns correct datediff results.

1.PNG

 

In your scenario, please check if the results are correct in Data view as shown in above screenshot. If you have several duplicate rows, when you add fields into table visual, [Diff PostingDate & DueDate] might be aggregated which returns larger values.

 


On a separate note, is it possible to show the DATEDIFF values on positive and negative values? If Posting Date is after the due date, I would like a positive value and not 0

 


You can use a IF condition in such a scenario. Similar to:

 

Diff PostingDate & DueDate =
VAR datediffval =
    DATEDIFF (
        'Sample Table'[Due Date].[Date],
        'Sample Table'[Posting Date].[Date],
        DAY
    )
RETURN
    IF (
        'Sample Table'[Posting Date].[Date] > 'Sample Table'[Due Date].[Date],
        ABS ( datediffval ),
        datediffval
    )
 
 
Best regards,
Yuliana Gu
Community Support Team _ Yuliana Gu
If this post helps, then please consider Accept it as the solution to help the other members find it more quickly.

Dear Yuliana,

 

Thank you so much for your answer.

 

You were right. I have duplicate dates and the results are right in Data View.

AlB
Community Champion
Community Champion

Hi @setis

Maybe if you share your pbix someone will  be able to help. It is hard like this, as you can see by the number of responses so far

Helpful resources

Announcements
November Power BI Update Carousel

Power BI Monthly Update - November 2025

Check out the November 2025 Power BI update to learn about new features.

Fabric Data Days Carousel

Fabric Data Days

Advance your Data & AI career with 50 days of live learning, contests, hands-on challenges, study groups & certifications and more!

FabCon Atlanta 2026 carousel

FabCon Atlanta 2026

Join us at FabCon Atlanta, March 16-20, for the ultimate Fabric, Power BI, AI and SQL community-led event. Save $200 with code FABCOMM.

Top Solution Authors
Top Kudoed Authors