Forum Discussion

Anonymous's avatar
Anonymous
Not applicable
8 years ago
Solved

Day Count between two dates - DAX Help

I have seen a number of posts about calculating the day count between two date.  None seem to address my specific use case.

 

I am tring to calculate the day count between a "Creation Date" and "Start Date".  Both are columns clearly identified in my dataset. Hoping someone from the community can help.  Those who have done it before, likely have an easy solution/suggestion.

 

I would appreciate any detailed instruction about it being a Measurment, Column, etc.  

 

Thanks in advance!

  • Anonymous's avatar
    Anonymous
    8 years ago

    Hi Anonymous,

     

    If you can't ensure which date column with be the small one, you should add some operation to get the specificity one.

     

    As I write above, min and max function can used to auto return the matched date.

     

    I build a sample table with random date store in date1 and date2, then I can use above formula to get the diff between these date column.

     

    Table formula:

    Sample = ADDCOLUMNS(GENERATESERIES(1,100,1),"Date1",RANDBETWEEN(DATE(2015,1,1),TODAY()),"Date2",RANDBETWEEN(DATE(2015,1,1),TODAY()))

     

    Calculate column:

    Diff = DATEDIFF(MIN([Date1],[Date2]),MAX([Date1],[Date2]),DAY) 

     

     

    Reuslt:

     

    Regards,

    Xiaoxin Sheng

9 Replies

    • Anonymous's avatar
      Anonymous
      Not applicable

      CanadaMGB

       

      Thanks for the feedback, though I am not sure this is a solution.  Based on the instructions it appears the solution you posted is giving me a day count between today and the Start Date.

       

      In my use case, I need to simply calc the day count between two specific columns.

      • Anonymous's avatar
        Anonymous
        Not applicable

        Hi Anonymous,

         

        Based on your description, I think DATEDIFF function will suitable for your requirement.

        Sample: calculate column.

         

        Day Count = DATEDIFF(MIN([Date 1],[Date 2]),MAX([Date 1],[Date 2]),DAY)

        DATEDIFF Function (DAX)

         

        Regards,

        Xiaoxin Sheng