Forum Discussion
Calculate difference between two dates power query
- 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])
jshutters,
Good question. Your question depends on the following:
1. Do you need the number of days between 2 dates?
Use Duration.Days ( [EndDate] - [StartDate] ) +1
2. Do you need the number of weekdays between 2 dates?
Generate a list of dates between start and enddate, and remove the weekends. Count the number of days left in your list.
3. Do you need working days between 2 dates?
Generate a list of dates between start and enddate, remove weekends and holidays. Then count the number of days left in your list.
For 2 and 3 I'll just drop this blog here so you can read the details. It's a bit more complex but replicates the DATEDIFF function for the M language:
https://gorilla.bi/power-query/working-days-between-dates/
Cheers!
Rick
--------------------------------------------------
@ me in replies or I'll lose your thread
Master Power Query M? -> https://powerquery.how
Read in-depth articles? -> BI Gorilla
Youtube Channel: BI Gorilla
If this post helps, then please consider accepting it as the solution to help other members find it more quickly.