Forum Discussion

erezbenmoshe's avatar
erezbenmoshe
Advocate I
6 years ago
Solved

DATEDIFF

DATEDIFF doesn't show the expected difference.  I am trying to calculate "Months from first purchase".  

Both columns are the same date format.  The difference I get is not correct.

 

This is a calcualted column:

Months from first purchase = DATEDIFF(FactSalesCache[FirstDate], FactSalesCache[Date], MONTH)
 
 

 

Thanks,

Erez

  • It looks like you pulled that column into a visual and the field is set to SUM.  My guess is the second line represents 3 records in your data set (4 months diff * 3 = 12) and the third line is covering 2 records.  Try changing the field to show the AVERAGE.

4 Replies

  • It looks like you pulled that column into a visual and the field is set to SUM.  My guess is the second line represents 3 records in your data set (4 months diff * 3 = 12) and the third line is covering 2 records.  Try changing the field to show the AVERAGE.

    • erezbenmoshe's avatar
      erezbenmoshe
      Advocate I

      You are right!! I am embarrassed that I did not figure it out myself 🙂

  • Could it be your date format? I tried with MM/DD/YYYY format and DATEDIFF works perfectly fine.

    Another alternate formula could be:

    DIFFERENCE = month('SAMPLE'[FIRSTSALE])-month('SAMPLE'[FIRSTPURCHASE])