DAX Function Guide

DATEDIFF
Empty image or helper icon

Sam McKay

CEO & Founder

How does the DATEDIFF work?
The DATEDIFF function (DAX) returns the count of interval boundaries crossed between two dates.
DATEDIFF Formula Syntax

DATEDIFF(
     <start_date>, <end_date>, <interval>
)

How do you use the DATEDIFF?

Used this function to determine the number of days between today and the first day of the year. You could also calculate the number of months between date values.

Related Blog Posts

Loading

Considerations when using the DATEDIFF?

The DATEDIFF function accepts three arguments: date_part, start_date, and end_date.

date_part is the part of date e.g., a year, a quarter, a month, a week that you want to compare between the start_date and end_date.

start_date and end_date are the dates to be compared. They must be resolved to values of type DATE, DATETIME, DATETIMEOFFSET, DATETIME2, SMALLATETIME, or TIME.

Related Video Tutorials

Loading

Formula examples using the DATEDIFF

DATEDIFF(MIN( Calendar[Date] ), MAX( Calendar[Date], second ) ) DATEDIFF(MIN( Calendar[Date] ), MAX( Calendar[Date], minute ) ) DATEDIFF(MIN( Calendar[Date] ), MAX( Calendar[Date], hour ) ) DATEDIFF(MIN( Calendar[Date] ), MAX( Calendar[Date], day ) ) DATEDIFF(MIN( Calendar[Date] ), MAX( Calendar[Date], week ) ) DATEDIFF(MIN( Calendar[Date] ), MAX( Calendar[Date], month ) ) DATEDIFF(MIN( Calendar[Date] ), MAX( Calendar[Date], quarter ) ) DATEDIFF(MIN( Calendar[Date] ), MAX( Calendar[Date], year ) )

= DATEDIFF (DATE (2016,1,1), DATE (2016,3,31), MONTH) returns 2. = DATEDIFF (DATE (2016,1,1), DATE (2016,4,1), MONTH) returns 3. = DATEDIFF (DATE (2016,1,1), DATE (2016,3,31), DAY) returns 90. = DATEDIFF (DATE (2016,1,1), DATE (2016,3,31), HOUR) returns 2160. = DATEDIFF (DATE (2016,1,1), DATE (2016,3,31), SECOND) returns 7776000.

DATEDIFF([StartDateTime],[EndDateTime], DAY) – ( CALCULATE ( COUNTROWS(‘Weekends’), ‘Weekends'[IsWeekend] = TRUE( ), DATESBETWEEN(‘Weekends'[Date], [StartDateTime],[EndDateTime]) ) )

Related Courses

Loading