Forum Discussion
slohombre
Oct 27, 2020Brass Contributor
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...
SergeiBaklan
Oct 27, 2020Diamond Contributor
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
Oct 27, 2020Brass 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?