DATEDIFF

Updated on

DATEDIFF is a DAX function that returns the number of units specified in the interval between two input dates.

Syntax

DATEDIFF(
   Date1,
   Date2,
   Interval
)
Argument Properties Description
Date1 A date in datetime format that represents the start date.
Date2 A date in datetime format that represents the end date.
Interval The unit that will be used to calculate, between the two dates.

Return Values

The count of interval boundaries between two dates.

Remarks

A positive result is returned if Date2 is larger than Date1. A negative result is returned if Date1 is larger than Date2.

Example

Examples in this article can be used with the sample Adventure Works DW 2020 Power BI Desktop model. To get the model, see DAX sample model.

The following DAX query:

EVALUATE
VAR StartDate =  DATE ( 2019, 07, 01 )
VAR EndDate =    DATE ( 2021, 12, 31 )
RETURN
    {
        ( "Year",     DATEDIFF ( StartDate, EndDate, YEAR ) ),
        ( "Quarter",  DATEDIFF ( StartDate, EndDate, QUARTER ) ),
        ( "Month",    DATEDIFF ( StartDate, EndDate, MONTH ) ),
        ( "Week",     DATEDIFF ( StartDate, EndDate, WEEK ) ),
        ( "Day",      DATEDIFF ( StartDate, EndDate, DAY ) )
    } 

Returns the following:

Value1 Value2
Year 2
Quarter 9
Month 29
Week 130
Day 914

Other functions related to DATEDIFF are:

Contribute » | Contributors: Rick de Groot
Microsoft documentation: https://learn.microsoft.com/en-us/dax/datediff-function-dax

2023-2024 © BI Gorilla. All rights are reserved. Information from Microsoft docs is property of Microsoft Corp. | Privacy Policy