Comprehensive Detailed Explanation
Requirement
We have two columns in Power Query Editor:
Order_Date
Shipping_Date
We need to calculate the number of days between the two dates.
Step 1: How date differences work in Power Query (M language)
Subtracting two date or datetime values in Power Query returns a duration value.
Example:
[Shipping_Date] - [Order_Date]
This produces a duration such as 3.00:00:00 (3 days).
Step 2: Converting duration into days
To get the number of days as an integer, we use Duration.Days().
Example:
Duration.Days([Shipping_Date] - [Order_Date] )
This returns 3 if the shipping date is 3 days after the order date.
Step 3: Evaluate other options
A. Duration.From → Converts a value to a duration type but does not extract the number of days.
B. Date.AddDays → Adds days to a given date, not used for calculating the difference.
C. Duration.Days → Correct, extracts total days from a duration.
D. DateTime.LocalNow → Returns the current system datetime, unrelated to this requirement.
References
Duration.Days function (Power Query M)
Working with dates in Power Query
Submit