Forum Discussion
jshutters
7 years agoResolver I
Calculate difference between two dates power query
How do I calculate the difference between two dates in Power Query M code (not DAX)? I'm looking for the number of days.
- 7 years ago
Hi jshutters
you need to use the duration functions: https://docs.microsoft.com/en-us/powerquery-m/duration-days
=each Duration.Days([Date1] - [Date2])
raymondwkmok
4 years agoFrequent Visitor
A further queston on Duration.Days, the formula Duration.Days([Date1] - [Date2]) did not cater both date inclusive situation. Is there any way to modify the formula for both date inclusve situation?
Example, The Duration.Days formula gives 6 for days between 2022/02/22 and 2022/02/28, but it should be 7 if both date inclusive.
storgall
3 years agoAdvocate I
Just add one day to the first date: Duration.Days(Date.AddDays([Date1],1) - [Date2])
Or just add one to the result: Duration.Days([Date1] - [Date2])+1