Forum Discussion

slohombre's avatar
slohombre
Brass Contributor
Oct 27, 2020

DAX Formula to get number of days between two dates?

Hi, all. I have developed a power pivot and I am seeking to find the number of days between two dates. I have tried DATEDIFF unsuccessfully. Any hints/tips on how to calculate this? On the screenshot below I am seeking to get the number of days between the "BeginHarvestDate" and the "PlantDate". Thanks for any help!

5 Replies

  • SergeiBaklan's avatar
    SergeiBaklan
    Diamond Contributor

    slohombre 

    As variant in DAX that could be as well

    =INT(Table1[End]-Table1[Start])

    but why don't you do this transformation in Power Query since the table generated in it. That's like

    ..., each Duration.Days(Duration.From([End]-[Start]))

    In general it's better to avoid calculated columns generated by DAX in data model if you can do them in Power Query.

    • slohombre's avatar
      slohombre
      Brass Contributor

      SergeiBaklan Thank you. I will execute this in Power Query - thanks for that advice. I am having trouble with your formula in the power query editor. I used:  Duration.Days(#duration[beginharvestdate]-[plantdate]) 

       

      That formula is yielding an expression error: We cannot apply field access to the type function. Details:

      Value=[Function]

      Key=beginharvestdate

       

      Any thoughts on what I am doing wrong?

Resources